These are chat archives for rust-lang/rust

20th
Oct 2016
Diego Giagio
@dgiagio
Oct 20 2016 03:46
Hi, I'm new to Rust. I'm looking for an Oracle database driver for Rust but can't find anything so far. Is that supported yet or I should use some C library with ffi? Thanks
Arthur Silva
@arthurprs
Oct 20 2016 07:29
@Biacode yeah, but since it's in a test I don't think it matters at all.
Sean Kerr
@seankerr
Oct 20 2016 14:38
Is it possible to do something such as the following: https://is.gd/MuS7xX
Maciej Hirsz
@maciejhirsz
Oct 20 2016 14:42
I’m not sure if you can implement traits for closures like that
in any case, this should bring you closer:
fn do_it<C: Caller>(caller: C) {
    caller.run("Test");
}
Sean Kerr
@seankerr
Oct 20 2016 14:43
Ahh, let me work with that. Thank you.
My brain is telling me this should be doable.
Maciej Hirsz
@maciejhirsz
Oct 20 2016 14:43
might have to use Box<Caller> though
Sean Kerr
@seankerr
Oct 20 2016 14:44
Now, why would I have to Box that closure, but I can a FnMut as a function argument and it works without being sized?
Maciej Hirsz
@maciejhirsz
Oct 20 2016 14:45
because you are using a trait to erase type information from the compiler
Sean Kerr
@seankerr
Oct 20 2016 14:45
Ahh
Maciej Hirsz
@maciejhirsz
Oct 20 2016 14:45
creating a reference (& or box) will create a trait object
Sean Kerr
@seankerr
Oct 20 2016 14:47
What would be the idiomatic way for a function to accept one or two closures as a single argument? Would I enum this?
I really want to avoid wrapping these closures in a variant. It just seems so... extra
Would that be much different than shoving them into a tuple?
Maciej Hirsz
@maciejhirsz
Oct 20 2016 14:48
tuple would have to have fixed size and amount of closures
I haven’t played with closures so much yet
Sean Kerr
@seankerr
Oct 20 2016 14:48
Ok, I appreciate your help ;)
Sean Kerr
@seankerr
Oct 20 2016 14:56
Seems to work with enums, but only with Fn, not FnMut since the closure is boxed. Doh.
Sean Kerr
@seankerr
Oct 20 2016 15:19
@maciejhirsz I got some assistance on IRC with a proper solution if you're curious.
Doesn't require boxing
Bradley Weston
@bweston92
Oct 20 2016 15:19
Share :)
Maciej Hirsz
@maciejhirsz
Oct 20 2016 15:20
aye
Now I'm trying to get it to work with 2 closures, since that's the point of this is to accept an argument of either a single closure, or a tuple of 2 closures. Trying to avoid 2 separate functions, but in the end I don't--at this point--know which will be nicer to work with
Sean Kerr
@seankerr
Oct 20 2016 15:35
Here we go, single or tuple: https://is.gd/jrcUPH
Maciej Hirsz
@maciejhirsz
Oct 20 2016 15:35
ah
generic trait
makes sense
seems my brain is too slow today
:+1:
Sean Kerr
@seankerr
Oct 20 2016 15:42
Same