These are chat archives for rust-lang/rust

17th
Aug 2017
Sherab Giovannini
@Shaddy
Aug 17 2017 13:57
wondering if there is a way to ensure that something is a concrete struct type by asserting
I do have a Generic::parse() that may return different Structs, so would be nice to test them asserting
Denis Lisov
@tanriol
Aug 17 2017 13:59
If you do know which one it should return, why not specify that explicitly?
Sherab Giovannini
@Shaddy
Aug 17 2017 13:59
for example?
assert_eq!(something::parse(), expected_struct{ ... })??
Denis Lisov
@tanriol
Aug 17 2017 14:00
How is the parse method defined?
I was thinking about something like
let result: ExpectedStruct = SomeTrait::parse(data);
Sherab Giovannini
@Shaddy
Aug 17 2017 14:02
so far it is Struct::parse(data) -> Enum(Command1, Command2, Command3 ...)
basically, I want to create a struct command by parsing a string, if string starts with say: /query, then it will produce a QueryCommand struct
just want to assert that if I do parse("/query whatever") it returns a QueryCommand object (if could be referred as object :D)
Denis Lisov
@tanriol
Aug 17 2017 14:05
In tests? You can do something like assert_eq!(Struct::parse("/query something"), Enum::QueryCommand("something"))
Sherab Giovannini
@Shaddy
Aug 17 2017 14:06
yep, its a bit more complex the produced object but seems that I would have to do it anyway
xD
Denis Lisov
@tanriol
Aug 17 2017 14:06
Well, you probably need to test that part too anyway :-)
Sherab Giovannini
@Shaddy
Aug 17 2017 14:08
thats true
Jonas Platte
@jplatte
Aug 17 2017 14:21
@Shaddy In cases where you really only want to check an enum variant, you can use assert_matches!
Or if you want to check the full structure but the type doesn't impl Eq.
Mahmoud Al-Qudsi
@mqudsi
Aug 17 2017 16:29
Is there an open issue tracking the discussion around getting Option to work with ?, implementing std::ops::Try for Option<_>?
Jonas Platte
@jplatte
Aug 17 2017 16:35
rust-lang/rust#31436
More specifically: rust-lang/rust#42526
Mahmoud Al-Qudsi
@mqudsi
Aug 17 2017 16:36
Thanks, @jplatte
My newly-created and immediately-closed issue #43944 should help when people search for std::opts::Try as I did.
GitHub issue searching is really bad when dealing with a project that has so many issues like rust-lang.
Jonas Platte
@jplatte
Aug 17 2017 17:17
Well just use DDG / Google then
That's how I found it