These are chat archives for rust-lang/rust

17th
May 2017
Mokilok
@Mokilok
May 17 2017 05:21
Hey, guys. I only heard about Rust yesterday but it seems like an interesting language. I was wondering if you guys would consider it to be at the stage where it should be used for production services and web apps?
Sean Leffler
@sdleffler
May 17 2017 05:21
Absolutely. As a matter of fact, Dropbox uses Rust in production.
They gave a talk on it a couple weeks ago, actually, at the SF Mozilla office - I was there. They quoted some really impressive speedups and reductions in memory usage.
@Mokilok here, if you're interested: https://air.mozilla.org/rust-meetup-may-2017/
They state tradeoffs you may be interested in w.r.t. what the actual developers involved thought about the language, what they liked and what they didn't
Talk's about 45 mins iirc but well worth it
Sean Leffler
@sdleffler
May 17 2017 05:27
To be totally fair, though, it's worth noting that it's not a total replacement of their production code with Rust. They've replaced a couple of components and been generally extremely happy with the results. The prior tooling iirc was written in Go.
sdleffler @sdleffler has a Rust Evangelism Strike Force sticker in the mail and plans to put it on his laptop...
Mokilok
@Mokilok
May 17 2017 05:28
Thanks for the info. It seems like it would be good for high performance cross platform services? How would it go for desktop applications.
I'm guessing the GUI libraries aren't quite there yet?
Sean Leffler
@sdleffler
May 17 2017 05:30
I don't know much about the state of the GUI libraries at the moment, but when I last looked, that was definitely the case. Things are starting to accelerate right now, though.
What I can tell you is you're not going to want to write your frontend code in Rust... WASM backend, not so ready yet :P
There are some nice CLI libraries but I assume you mean GUI GUI :P
Fra ns
@snarf95_twitter
May 17 2017 06:12
this version is using fold and replacing filter_map with map->filter->map. what do people think about readability of the three iterations?
geekyi
@geekyi
May 17 2017 07:21
@Mokilok if you're looking for cross platform GUI, you should take a look at RED. Still really alpha, but works mostly on windows and partially on Mac. Would be interesting to see how a combination of it and rust would do
Joonas Koivunen
@koivunej
May 17 2017 08:32
@geekyi could you link to RED? my google-fu is not too strong today
@Mokilok there is https://github.com/PistonDevelopers/conrod which might be of interest
Joonas Koivunen
@koivunej
May 17 2017 08:35
@geekyi ah yes, i missed your "would be interesting to see how a combination of it and rust ..." and discarded the red language from google results...
Jonas Platte
@jplatte
May 17 2017 08:37
@sdleffler There are Rust Evangelism Strike Force stickers? Do they ship to Europe? Where can I get one? :D
Andrew Thorburn
@ipsi
May 17 2017 08:56
@sdleffler @Mokilok I know there's also a company in London that's using Rust for various things. I forget the exact name, but one of my former colleagues works there, and seems to be enjoying Rust so far.
Andrew Thorburn
@ipsi
May 17 2017 09:18

Is there a way in Rust to say "Is this enum variant to the variant EnumType::Variant1" if the enum doesn't implement PartialEq? The problem I'm trying to solve is that I've got a method returning a Result<Async<Thing, CustomErr>> (where Async is from Tokio), and trying to test that looks like it will involve a bunch of boilerplate like:

        match future.poll() {
            Ok(a) => {
                match a {
                    Async::NotReady => assert!(true),
                    _ => assert!(false),
                }
            },
            _ => assert!(false),
        }

I can simplify that into

        match future.poll().unwrap() {
            Async::NotReady => assert!(true),
            _ => assert!(false),
        }

Ideally, I would like to do

assert_eq!(future.poll().unwrap(), Async::NotReady)

But that won't compile as Async doesn't implement PartialEq - is there any way around this, or is the match my only solution?

David McGillicuddy
@djmcgill
May 17 2017 09:18

I'm looking through the code for smallstring, and notice things like this a lot:

impl<B: Array<Item=u8>> std::cmp::PartialEq for SmallString<B> {
    fn eq(&self, other: &Self) -> bool {
        let (s1, s2): (&str, &str) = (self, other);
        s1 == s2
    }
}

Is there a difference between casting that way as opposed to doing it like: (self as &str) == (other as &str)?

Jonas Platte
@jplatte
May 17 2017 09:21
@ipsi You can use nested matching, so your first example is equivalent to:
match future.poll() {
    Ok(Async::NotReady) => assert!(true),
    Ok(_) => assert!(false),
    _ => assert!(false),
}
And then you can also remove the second branch because it's covered by the third
But there might also be an assert_match or something, let me check..
Andrew Thorburn
@ipsi
May 17 2017 09:24
Huh, that's quite nice!
Jonas Platte
@jplatte
May 17 2017 09:30
So there's not assert_match in the standard libary, but there is a crate that does exactly that: https://crates.io/crates/assert_matches
Andrew Thorburn
@ipsi
May 17 2017 09:30
Handy.
Jonas Platte
@jplatte
May 17 2017 09:30
With that, your example should become assert_matches!(future.poll(), Ok(Async::NotReady)); :)
Andrew Thorburn
@ipsi
May 17 2017 09:31
That is very nice. I will give that a try, thanks!
Andrew Thorburn
@ipsi
May 17 2017 09:59
That works. Was not as straight-forward to get working as expected (#[derive(Debug)], and again, and -- oh bugger, can't do Box<Trait + Send + Debug> - manual impl time!), but got there.
Zakarum
@omni-viral
May 17 2017 10:12
Why there is no Div<Duration> for Duration?
Denis Lisov
@tanriol
May 17 2017 10:13
What should it return, in your opinion?
Zakarum
@omni-viral
May 17 2017 10:13
Well. u128 can hold the result )
Jonas Platte
@jplatte
May 17 2017 10:15
It has apparently been proposed before but would have been backwards-incompatible: rust-lang/rust#32515
Zakarum
@omni-viral
May 17 2017 10:15
This is different
Jonas Platte
@jplatte
May 17 2017 10:17
Actually, now that I look at it, you're right. (assuming you're talking about the workaround, not the issue)
Zakarum
@omni-viral
May 17 2017 10:17
Here is my problem
I have a value which holds duration of single animation frame
I have a value which holds duration since start of animation
I want to devide ‘em to get current animation frame
For workaround I just you u64 instead of Duration
But looking for better solution
The problem is that not even f64 can hold the result of Duration / Duration
I assume this is the reason for lacking Div<Duration> for Duration in std
Andrew Thorburn
@ipsi
May 17 2017 10:41
Something minor that would be really helpful: If I set #![deny(unused_must_use)], I would like to see unused_must_use errors reported with other compile errors, or at least as the final output from the build, but definitely not mixed in with all the other warnings. Mostly because I have a huge number of unused warnings (which is fine - generated code that I'm slowly implementing), but makes it really hard to find the unused_must_use error...
Jonas Platte
@jplatte
May 17 2017 12:39
@ipsi You could, as a workaround, add #![allow(whatever)] to make those other warnings go away for now
Zakarum
@omni-viral
May 17 2017 12:55
#![allow(sytnax_error)] and find all unused first
Zakarum
@omni-viral
May 17 2017 13:09
@jplatte Now I realized how to clone std::iter::FilterMap
You just have to make it not like some_iter.filter_map(|value| predicate(value))
But some_iter.filter_map(&|value| predicate(value))
mhsjlw
@mhsjlw
May 17 2017 14:14
I'm trying to use CURL to make a form post request
is there anyway I can persist cookies between requests?
without saving to a file?
(the curl crate)
Fra ns
@snarf95_twitter
May 17 2017 16:30