« first day (2172 days earlier)      last day (1302 days later) » 

9:06 AM
If I told you I dreamed about GATs, I'd be lying. But would still love to have GATs.
 
9:35 AM
So you would've had a Grand Apparition Testimonial
Either way, I'd like to have it, every-single-flippin'-day
 
a Greasy Amber Tree
 
10:12 AM
You're getting Good At That!
(Shoul've been "This", but whatever.. I can't edit it anymore..)
 
Gotta Aim Topwards
(alas, with a made-up word)
 
10:30 AM
You have 5 variables of type Option<&str>. You want to check that exactly one of them is Some. What's the concise and clean way ?
I tried those : play.rust-lang.org/…
Oh, xor works for this
 
 
2 hours later…
12:24 PM
@DenysSéguret that might be the only time I’ve ever seen that used.
 
Never used it before (on options)
 
@DenysSéguret Some(1).xor(Some(2)).xor(Some(3)).xor(Some(4)).xor(Some(5)) is Some(5)
@DenysSéguret this is not what you were looking for? Or you can make it work?
 
12:40 PM
Damn
@trentcl I just hadn't checked this case
 
match (a, b, c, d, e) {
    (x, None, None, None, None) |
    (None, x, None, None, None) |
    (None, None, x, None, None) |
    (None, None, None, x, None) |
    (None, None, None, None, x) => x,
    _ => None,
}
well that would get you the unique Some, I guess maybe it's not optimal if you just need a boolean
 
Yes, my question is more about the check
It's for configuration checking and raising an appropriate error message
 
[&a, &b, &c, &d, &e].iter().flat_map(|x| x.as_ref()).count() == 1?
 
interesting. Too obscure for real code but I like the idea of flat_map here
What I find painful is the as_ref
 
1:17 PM
[&a, &b, &c, &d, &e].iter().filter(Option::is_some).count() == 1
Untested; on mobile
 
@Shepmaster you need filter(|x| x.is_some()) unfortunately
 
My nemesis
At least it’s shorter
Or is it the same
Whatever
 
@Shepmaster it's a couple characters shorter
wait, no, I just can't count. Same length I guess.
 
 
3 hours later…
4:01 PM
(removed)
4
 
Silly me
@Shepmaster I literally asked this again
 
Speaking of lessons, what's the best way to debug this: I have a function that I wrote and I'm unit-testing it. The function is returning an Err variant and I need to quickly figure out which path it's taking.
Currently the best I can think of is stepping though it with gdb
The reason I'm not used to this is because say if I have a function throwing an exception, I get the stack trace for free
But here it's just a return value so AFAIK there's no way to get the stack trace just like that?
 
@EnnMichael if you use a library like my SNAFU, you can add backtraces to errors.
But even better, if you use SNAFU right (aka how I say you should) you don’t need it because every error can only appear exactly once with a given context.
 
@Shepmaster Thanks, is this what people normally do?
 
I am people.
 
Great
 
4:40 PM
But what you said is still true. If you return the same value (error or not) from two places in a function, that value cannot tell you where it came from.
You’d have to use a debugger or other equivalent tool to watch the execution path.
 
Umm, about SNAFU
I think there's a mistake in the "quick example"
I might be wrong, but I think you forgot to include use Error::*
You're using OpenConfig and SaveConfig without the Error:: path
Maybe I'm wrong though and there's some macro magic going on?
 
4:57 PM
you confuse variant and enum, variant can't be imported
OpenConfig is a struct generate by snafu, not the variant Error::OpenConfig
 
@EnnMichael indeed magic.
@Stargateur sure they can. That’s how None or Ok work
 
@Shepmaster I'm tired
 
@EnnMichael remember that examples in Rust docs are tests by default
 
@Shepmaster Yeah I thought of that later
Feels weird to me
 
@EnnMichael it’s the single strangest thing of the library
If the generated types were called ...Context would that be more obvious?
 
5:13 PM
@Shepmaster It would make it more obvious that there's something special going on
I mean, I feel like most people don't like non-obvious macros
I definitely don't like non-obvious macros, e.g. select! evokes more negative emotions than dbg! or println!
How do I debug tests?
I can do cargo test foo --no-run but I don't know the output binary name... :|
 
@EnnMichael That's a common struggle.
 
5:36 PM
new highlighting is live
I like it better
 
5:49 PM
@EnnMichael The easiest is to run it (maybe with --verbose) and just look at the binary name
 
@Shepmaster Ah, thanks
 
 
3 hours later…
9:26 PM
@FrancisGagné Sounds very interesting, cheers for the share!
 

« first day (2172 days earlier)      last day (1302 days later) »