These are chat archives for rust-lang/rust

28th
Nov 2017
Zakarum
@omni-viral
Nov 28 2017 07:29
@nyarly You always can create PR to the crate where IntoTemplateVar is defined.
Judson Lester
@nyarly
Nov 28 2017 18:24
That's what I'm contemplating.
Just when I thought I was starting to understand moves and borrows: https://github.com/nyarly/d2tools/blob/master/src/destiny/mod.rs#L194-L197
src/destiny/mod.rs|196 col 38 error 597| `**db` does not live long enough
||     |
|| 194 |         .and_then(|ref item| {
||     |                   ---------- capture occurs here
|| 195 |           let mut item = item.clone();
|| 196 |           item.fetch_component_defs(&db);
||     |                                      ^^ does not live long enough
|| ...
|| 199 |       }).collect::<Vec<_>>() );
||     |                            - borrowed value only lives until here
|| ...
|| 217 | }
||     | - borrowed value needs to live until here
I mean, really, I need the DB connection long enough to make some queries and update that struct. Then I'm done with it.
I can't seem to explain that to rustc though
Dirk Van Haerenborgh
@vhdirk
Nov 28 2017 18:35
Hi
Could someone explain to me what this syntax means?
pub struct SslAcceptorBuilder(SslContextBuilder);
I don't know what this contruct is called, and searching the docs has led me nowhere so far
Aleksey Kladov
@matklad
Nov 28 2017 18:37
newtype struct is the canonical name for this pattern
Dirk Van Haerenborgh
@vhdirk
Nov 28 2017 18:38
aha, thank you!
is there a way to 'upcast' to that abstracting struct?
Aleksey Kladov
@matklad
Nov 28 2017 18:40
Hm, not sure I undestand the question...
It is a struct
Dirk Van Haerenborgh
@vhdirk
Nov 28 2017 18:41
well, the point is that I am holding an instance of SslContextBuilder
Aleksey Kladov
@matklad
Nov 28 2017 18:41
you can get access to the single field using indexing access mySslAcceptorBuilder.0 or pattern matching let SslAcceptorBuilder(ctxBuilder) = mySslAcceptorBuilder
Dirk Van Haerenborgh
@vhdirk
Nov 28 2017 18:41
but functions that accept an SslAcceptorbuilder do not accept SslContectBuilder
Steve Klabnik
@steveklabnik
Nov 28 2017 18:41
not in this case because the wrapped struct isn't pub, no?
Aleksey Kladov
@matklad
Nov 28 2017 18:42
Yep
Dirk Van Haerenborgh
@vhdirk
Nov 28 2017 18:42
the wrapped struct is pub, but I can't assign 0 myself
Aleksey Kladov
@matklad
Nov 28 2017 18:42
I think the build method is what you would want to call at some point: https://cyderize.github.io/rust-websocket/doc/openssl/ssl/struct.SslContextBuilder.html#method.build
Dirk Van Haerenborgh
@vhdirk
Nov 28 2017 18:42
well yes, I have all that
I have an sslcontextbuilder and a sslcontext as a result
however, I wanted to use tokio_openssl 's SslAcceptorEx to asynchonously do the whole ssl verification stuff
but, I can't seem to find how I am supposed to go from an SslContext to an SslAcceptor
the only way to make an SslAcceptor seems through its builder, which is how I ended up here
Aleksey Kladov
@matklad
Nov 28 2017 18:46
Ok, sounds like a fun graph problem, (and a bit like Java :) ) :)
Dirk Van Haerenborgh
@vhdirk
Nov 28 2017 18:47
I'm surprised I'm not using factories yet...
Aleksey Kladov
@matklad
Nov 28 2017 18:47
So, you have an SslContext, and you need an SslAcceptor? And the only way to get SslAcceptor is through the builder?
Dirk Van Haerenborgh
@vhdirk
Nov 28 2017 18:47
seems like that, yes
I could simply use the SslAcceptorBuilder, but I'm not sure if all the 'mozilla' stuff it comes with is needed(or wanted) in my case
(since sslacceptorbuilder wraps sslcontextbuilder)
Aleksey Kladov
@matklad
Nov 28 2017 18:53
Hm, yeah, I think real experience with openssl is required to find the ends here... Looks like this ultimatelly bottoms out at the SslMethod layer: https://docs.rs/openssl/0.9.21/src/openssl/ssl/connector.rs.html#28
Dirk Van Haerenborgh
@vhdirk
Nov 28 2017 18:54
seems to me this is a pimpl idiom, and so the conversion I'm after is what they try to avoid...
Judson Lester
@nyarly
Nov 28 2017 18:55
Is there a way to inspect how lifetimes are determined? I'm kind of stumped on my error above.
Dirk Van Haerenborgh
@vhdirk
Nov 28 2017 18:55
hmm, if there's no way around this, I'll simply have to pull all of the relevant parts from tokio_openssl into something of my own
thanks anyway
Judson Lester
@nyarly
Nov 28 2017 19:00
Like, I've learned to use () = to inspect type inferences, but I really don't understand why db needs to live so long
Denis Lisov
@tanriol
Nov 28 2017 19:07
@nyarly Note that your db is an argument in line 185 and will be dropped in line 201 at the end of that closure.
At the same time, it's captured inside the structure representing f which you return from the same closure.
Judson Lester
@nyarly
Nov 28 2017 19:09
Right - I'm having trouble in this case understanding why that's a problem.
Denis Lisov
@tanriol
Nov 28 2017 19:09
Am I missing something?
Judson Lester
@nyarly
Nov 28 2017 19:09
By virtue of being an argument to a &mut self method?
I am certain that it's me that's missing something.
Why is db captured?
OH
Because the future hasn't been executed yet, obvs.
Judson Lester
@nyarly
Nov 28 2017 19:15
Thanks, @tanriol
I needed to step back a bit.
Zakarum
@omni-viral
Nov 28 2017 20:25

After updating to the latest rustc I've started to receive errors like this

expected type `serde::export::Result<T, E>`
               found type `E`

While the type is common std::result::Result

Zakarum
@omni-viral
Nov 28 2017 20:30
I see that serde::export::Result is an alias to std::result::Result.
But why it appears in error instead of actual type when I don't import serde::export::Result?
Steve Klabnik
@steveklabnik
Nov 28 2017 21:29
seems strange