These are chat archives for rust-lang/rust

21st
Feb 2018
luxbock
@luxbock
Feb 21 2018 11:10 UTC
is there a way to create a set and insert an item(s) into it in one expression, so that I could create one inside a closure?
Michal 'vorner' Vaner
@vorner
Feb 21 2018 11:16 UTC
@luxbock First, a block is also an expression. So you don't have to be limited to simple statements. This is valid:
|| {
    let mut x = HashSet::new();
    x.insert(42);
    x
}
Second, vec![42, 43].into_iter().collect::<HashSet<_>>()
Third, there's a crate (sorry, don't remember the name) somewhere that provides a macro for these things.
luxbock
@luxbock
Feb 21 2018 11:22 UTC
@vorner thanks
Ingvar Stepanyan
@RReverser
Feb 21 2018 13:17 UTC
@vorner @luxbock I guess you mean this crate https://github.com/bluss/maplit
Michal 'vorner' Vaner
@vorner
Feb 21 2018 13:18 UTC
That would be one of them. I think there's at least 5 different ones.
Edouard Menayde
@edouardmenayde
Feb 21 2018 14:48 UTC
Hi, I'm wondering to deal with error handling in rust using the new ? operator : the problem being each library has its own Error type thus if I use ? in a function that return Result<(), whatever> it won't work because I don't have a one fits all type for those errors that might be returned by ?. Is there a way to deal with that ?
Andy Grove
@andygrove
Feb 21 2018 14:48 UTC
pub enum ExecutionError {
    IoError(Error),
    CsvError(csv::Error),
    ParserError(ParserError),
    Custom(String)
}

impl From<Error> for ExecutionError {
    fn from(e: Error) -> Self {
        ExecutionError::IoError(e)
    }
}

impl From<String> for ExecutionError {
    fn from(e: String) -> Self {
        ExecutionError::Custom(e)
    }
}
basically you can implement From<> to convert between different error types
Edouard Menayde
@edouardmenayde
Feb 21 2018 14:50 UTC
@andygrove Thanks a lot that's nice :) I hope I would not have to do that but it still is a good solution :-) Have a good day ;)
Edoardo Luppi
@lppedd
Feb 21 2018 16:06 UTC
Hi everyone! I'm looking for ways to experiment with Rust and its features. Do you have any suggestion?
Daniel Chao
@bioball
Feb 21 2018 16:17 UTC
hey folks, question here
would appreciate if anybody could answer it!
Steve Klabnik
@steveklabnik
Feb 21 2018 16:24 UTC
@bioball answered
Daniel Chao
@bioball
Feb 21 2018 16:25 UTC
thanks steve!
Steve Klabnik
@steveklabnik
Feb 21 2018 16:25 UTC
no problem!
Kelly Thomas Kline
@kellytk
Feb 21 2018 18:37 UTC
Is it possible to disable type inferrence?
Dylan DPC
@Dylan-DPC
Feb 21 2018 18:39 UTC
why would you want to do that?
Kelly Thomas Kline
@kellytk
Feb 21 2018 18:40 UTC
<masochist>I prefer explicit static typing</masochist>
Steve Klabnik
@steveklabnik
Feb 21 2018 18:40 UTC
it is not possible to disable type inference
Kelly Thomas Kline
@kellytk
Feb 21 2018 18:40 UTC
Pity, thanks @steveklabnik
Eliza Weisman
@hawkw
Feb 21 2018 18:40 UTC
you can just, you know, put explicit type annotations on everything?
Kelly Thomas Kline
@kellytk
Feb 21 2018 18:41 UTC
Which I do, however it lacks enforcement in cases where I accidentally omit it
WaDelma
@WaDelma
Feb 21 2018 18:41 UTC
Make lint for that?
Eliza Weisman
@hawkw
Feb 21 2018 18:41 UTC
i’m sure it would be possible to write a clippy lint for that or something
Yeah :point_up:
Kelly Thomas Kline
@kellytk
Feb 21 2018 18:42 UTC
Great idea, thanks @WaDelma
Dylan DPC
@Dylan-DPC
Feb 21 2018 18:42 UTC
yeah i agree
WaDelma
@WaDelma
Feb 21 2018 18:43 UTC
dunno how well it would work with voldemort types though.
Kelly Thomas Kline
@kellytk
Feb 21 2018 18:43 UTC
What is that?
hawkw @hawkw realised @kellytk was asking about “voldemort types”, sorry
Eliza Weisman
@hawkw
Feb 21 2018 18:44 UTC
i think @WaDelma means types which are unnameable
WaDelma
@WaDelma
Feb 21 2018 18:45 UTC
yeah
well impl trait would probably make that easier
Kelly Thomas Kline
@kellytk
Feb 21 2018 18:45 UTC
Oh
WaDelma
@WaDelma
Feb 21 2018 18:45 UTC
and you could make the lint to ignore those
Eliza Weisman
@hawkw
Feb 21 2018 18:47 UTC
A lot of things like e.g. iterators or futures are going to be exceedingly painful without type inference…just a warning
Kelly Thomas Kline
@kellytk
Feb 21 2018 18:51 UTC
Thanks @WaDelma and @hawkw for the heads up
François Dubois
@francoisduboisx_twitter
Feb 21 2018 20:17 UTC
Hi. Does anybody use mio ? I want to do async, but have questions and don't find answer.
Aleksey Kladov
@matklad
Feb 21 2018 20:19 UTC
@francoisduboisx_twitter I think these day most of the folks use https://tokio.rs/ for async stuff, which is build on top of mio
François Dubois
@francoisduboisx_twitter
Feb 21 2018 20:33 UTC
Yeah, I looked tokio, but if you want to use the async/await stuff, you need to be on the nightly build of rust. Not sure it makes sense to build an application on something that is not stable
Steve Klabnik
@steveklabnik
Feb 21 2018 20:34 UTC
that's also true of mio though
the tokio gitter might be a good place to ask about mio
François Dubois
@francoisduboisx_twitter
Feb 21 2018 20:34 UTC
Ok thanks
Denis Lisov
@tanriol
Feb 21 2018 20:38 UTC
@francoisduboisx_twitter The async/await stuff is optional and Tokio is (not perfectly, but) usable on stable too.
François Dubois
@francoisduboisx_twitter
Feb 21 2018 20:40 UTC
Yeah, agree, but without async/await stuff, it seems really hard to use and not intuitive
your code become quickly hard to read. Of course, I just looked at it quickly
Erich Cordoba
@ericho
Feb 21 2018 23:14 UTC
Hi, what’s the difference between for &i in list.iter() and for i in list.iter() ?
Eric Moritz (he/him)
@ericmoritz_twitter
Feb 21 2018 23:29 UTC
&i derefs the value so for &i in vec![1,2,3].iter() i is of type i32 but for i in vec![1,2,3].iter() i is of type &i32