> Result<(), ()> is just a spicy bool.
EDIT: quoted wrong part of parent, ignore above
> match x { true => {} false => {} }
I really like this. Pattern matching syntax is great, nice to use in place of if/else as much as possible
EDIT: quoted wrong part of parent, ignore above
> match x { true => {} false => {} }
I really like this. Pattern matching syntax is great, nice to use in place of if/else as much as possible
There's a nice alternative though, which is empty struct errors.
#[derive(Debug, thiserror::Error, displays of::Display)]
/// Frobnicating the foo failed.
struct FrobError;
The advantage is the standard advantages types use, i.e. if I want to propagate it I know this specific zero sized type has a specific meaning. It'll also show a nice message if you print it. let plural = match cases.len() > 1 {
true => "s",
false => "",
};
Of course, you'd more likely have something like let prefix = match cases.len() {
0 => "no values".to_string(),
1 => "a value".to_string(),
n => format!("{} values", n),
}; let plural = match cases.len() {
1.. => "s",
0 => "",
};
;P let plural = match cases.len() {
0 | 2.. => "s",
1 => "",
};
or something (though to be fair the original code snippet also handled "0" incorrectly -- should be "cases.len() != 1").