These are chat archives for rust-lang/rust

21st
Mar 2019
Riley Cat
@WreckedAvent
Mar 21 03:54
the npm stuff is used because that's just the reality of modern front end development
you could take the wasm and just stick it in an html file if you wanted to but there's a reason it uses webpack etc
Luca-A-Mueller
@Luca-A-Mueller
Mar 21 13:40

Hi there, I was wondering if it is possible to do an .inner_join on a IntoBoxed<'a, Self, DB> type ...
Trying out

let mut query = posts::table.into_boxed();
query = query.filter(post.ne_all(excluded_all_state));
query.inner_join(users).load(conn)?

gives me a the trait diesel::Queryable<(... is not implemented for (Post, User) error.

Victor Lopes
@vlopes11
Mar 21 20:23
Hello Rustaceans! Anyone build windows binaries in linux environments? If yes, which CI / tool / container / (?) you use?
Peter Atashian
@retep998
Mar 21 20:23
Most people have appveyor or travis CI build their windows binaries for them
or just actually have a Windows system to do stuff on
Denis Lisov
@tanriol
Mar 21 20:24
What kind of binaries? I've built some special-use servers for windows-gnu by "just" cross-compiling.
Peter Atashian
@retep998
Mar 21 20:24
it is possible to cross compile to Windows if you get MinGW-w64 setup correctly
Victor Lopes
@vlopes11
Mar 21 20:28
I suppose some cross-compiling should do the trick. Nothing special about the binaries, just regular ones. I'll check the gnu options and appveyor, thanks.
Denis Lisov
@tanriol
Mar 21 20:31
IIUC, the usability of the gnu (MinGW) option depends on whether you need to work with non-Rust libraries built for Windows (not sure, possibly also some Windows API features?)
Victor Lopes
@vlopes11
Mar 21 20:34
I'm using only rust libraries in this case.
The targets are windows, linux and osx. But, seems circleCi will support osx, but not windows. And appveyor supports windows + linux. lol
Stephen Carman
@hntd187
Mar 21 20:36
I have a kinda gross collection of if let Ok(x) = ... statements nested
is there a way to chain them together better
Ichoran
@Ichoran
Mar 21 20:37
I generally use ? instead in that case.
let x = thingThatMightFail()?;
Stephen Carman
@hntd187
Mar 21 20:38
I'm in a closure I cannot use ?
Ichoran
@Ichoran
Mar 21 20:39
If you don't need to handle anything but the success case you can gather them all together in a tuple and match out the all-success case.
match (a, b, c, d) { (Ok(xa), Ok(xb), Ok(xc), Ok(xd)) => ... }
But if you need to use previous results to generate later ones, and can't just have the closure call another function where the arguments are listed explicitly (and can then use ?), it does get kinda gross, as you say.
Stephen Carman
@hntd187
Mar 21 20:42
guess I'm just stuck in that case
I know you'll appreciate this @Ichoran but I was looking for a scala for comprehension here basically
Denis Lisov
@tanriol
Mar 21 20:42
Why not a helper function?
Ichoran
@Ichoran
Mar 21 20:42
Yeah, well, I have basically abandoned for-comprehensions in favor of a macro that emulates ? :joy:
But I agree with @tanriol that you should carefully evaluate whether you can use a helper function.
I tend to do that in both Scala and Rust.
Stephen Carman
@hntd187
Mar 21 20:45
can you give me an example of what you mean
Obviously a toy example, but it shows a closure that captures something from the environment deferring its computation to a helper function that uses ? to propagate errors.
You can write the function inside the closure too if you are worried about restricting visibility of the helper function (but unlike in Scala, Rust functions can't see the scope, so you have to make the arguments explicit): https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=8b9017ffc07a45bc1104a495fcd256fc
Aleksandrov Vladimir
@invis87
Mar 21 20:59

Hi guys! I am new to rust and wonder of it modules system... :D
My file structure is:

> ls src
main.rs  my

> ls src/my
bar.rs  baz.rs  mod.rs

Ok, I understand how to call functions from bar & baz inside main.rs. But how to call functions from bar inside baz ??

Denis Lisov
@tanriol
Mar 21 21:06
use crate::my::bar::function_name;
Or use super::bar::function_name;
Aleksandrov Vladimir
@invis87
Mar 21 21:08
wow, thanks much!
matrixbot
@matrixbot
Mar 21 21:52
moltonel Stephen Carman (Gitter): https://github.com/JoshMcguigan/multi_try maybe ?
Riley Cat
@WreckedAvent
Mar 21 22:08
don't forget about and_then
Ichoran
@Ichoran
Mar 21 23:07
( @hntd187 - If it helps,and_then is called flatMap in Scala, and is what for comprehensions desugar to except for the innermost thing which is map (and also is for Rust. You won't necessarily avoid the nesting, though; Scala for comprehensions don't look nested syntactically but they are computationally, so a literal translation is going to have nesting. )
Riley Cat
@WreckedAvent
Mar 21 23:49
you can avoid the nesting in a lot of ways, though
the easiest way is to just design your functions to be a pipeline where each step explicitly takes as input the output from the last step