These are chat archives for rust-lang/rust

12th
Feb 2018
kristopher tate
@kristate
Feb 12 2018 01:14
@matklad Following-up: thank-you again for your help, the Struct::<TestEnum>::test() syntax worked correctly.
Dylan DPC
@Dylan-DPC
Feb 12 2018 12:35
Is there a way i can share a value between 2 tests?
Aleksey Kladov
@matklad
Feb 12 2018 12:39
@Dylan-DPC global variable? Like an std::sync::Mutext wrapped into a lazy_static!
Dylan DPC
@Dylan-DPC
Feb 12 2018 12:45
well its not static variable. I actually need a value from response of one test in another test @matklad
Aleksey Kladov
@matklad
Feb 12 2018 12:57
Hm, then I think it should be possible to write a single #[test] function which calls two other functions? #[test] fn test_a_and_b() { let a = test_can_make_a(); test_can_use_a(a); }?
Dylan DPC
@Dylan-DPC
Feb 12 2018 13:02
yeah that's what I am doing right now. Thanks :smile:
Casey Allred
@sbditto85
Feb 12 2018 17:51

I've got a newb question, I have a custom error type that I'd like to implement StdError for. The custom error type is an enum with an embedded type that I'd like to include the error with. Something like:

pub enum Error {
    IoError(io::Error),
}

impl StdError for Error {
    fn description(&self) -> &str {
        match *self {
            Error::IoError(ref ioError) => format!("IO Error: {}", ioError.description()).as_str()
        }
    }
}

the problem is that it my return &str doesn't live long enough. How do I include the embedded error type as part of my error message? or is that not possible?

Roman Proskuryakov
@kpp
Feb 12 2018 17:54
Aleksey Kladov
@matklad
Feb 12 2018 17:54
@sbditto85 in general, StdError::description method should not be relied upon. There's even an RFC for deprecating it
Instead, you should use and implement std::fmt::Display for your errors
And yeah, abandoning std::error::Error altogether and going with failure is also an infallible choice =)
Casey Allred
@sbditto85
Feb 12 2018 17:55
oh ... ok, well i got that working so i guess i'm ok
Daniel Bischof
@dbischof90
Feb 12 2018 19:18
Hey guys
Is it possible to program a match-like statement when the variants to match are not known at compile-time?
For example if I had a couple of strings from a database and would now want to match another string against it
Denis Lisov
@tanriol
Feb 12 2018 19:21
A fixed number of strings and actions?
Daniel Bischof
@dbischof90
Feb 12 2018 19:21
Yes, the variants would not change during the runtime
I have the feeling this could be a
Denis Lisov
@tanriol
Feb 12 2018 19:27
match with guards?
Daniel Bischof
@dbischof90
Feb 12 2018 19:27
Macro of some sort...
What do you mean?
Denis Lisov
@tanriol
Feb 12 2018 19:29
match kwd {
    s if s == my_command_a => { ... },
    ...
}
Daniel Bischof
@dbischof90
Feb 12 2018 19:31
Yeah, just found that
Cool feature
Hmm but a little bit more static - let's assume I have a collection of strings and want match against an input string. Neither are known at compile-time. How would that look like?
Dylan DPC
@Dylan-DPC
Feb 12 2018 19:45
Anyone here who has used http crate? If i have a String named path, how can I do
Request::builder().uri(path) ?
I get: the trait foo:http::HttpTryFrom<std::string::String> is not implemented for foo::http::Uri
Dylan DPC
@Dylan-DPC
Feb 12 2018 19:52
got it working by changing it to a &str
damn me :smile:
Thibault Delor
@thibaultdelor
Feb 12 2018 23:36
Hey there, what the status of rustup?
Hans W. Uhlig
@huhlig
Feb 12 2018 23:36
its in heavy use?
Thibault Delor
@thibaultdelor
Feb 12 2018 23:37
Seems like there is a huge number of issues and PR but no one to look at it
Hans W. Uhlig
@huhlig
Feb 12 2018 23:37
last commit was about 2 weeks ago
Thibault Delor
@thibaultdelor
Feb 12 2018 23:39
yeah so some people can commit, but if I want to i have to go thrugh a PR, seeing some PR from 4months ago without a single comments isnt encouraging?
and seeing 270 open issues isn’t either
I am happy to get involved with rustup though, not sure who to engage
Hans W. Uhlig
@huhlig
Feb 12 2018 23:50
I would prorobly post here https://internals.rust-lang.org/
Thibault Delor
@thibaultdelor
Feb 12 2018 23:50
@huhlig thanks, will do