This is only vaguely related to language design, and only vaguely related to rust internals (arguably it's more about rust users). However, we find ourselves increasingly often using code of the form:
return something_else.mutate() && {
something = something_else;
true
}
In particular:
/// Advances the instruction address register.
///
/// # Returns
///
/// `true` if successful, `false` otherwise.
fn next(&mut self) -> bool {
let new = self.iar.map_or(0, |v| v + 1);
new < self.ops.len() && {
self.iar = Some(new);
true
}
}
/// Rewinds the instruction address register.
///
/// # Returns
///
/// `true` if successful, `false` otherwise.
fn prev(&mut self) -> bool {
let new = self.iar.expect("iar").checked_sub(1);
new.is_some() && {
self.iar = new;
true
}
}
/// pattern <- ( subtree / unexpected_token ) ( !. / unexpected_token )
fn pattern(&mut self, s: &mut &str) -> Result<bool, PatternError> {
let mut cursor = *s;
Ok(
(
self.subtree(&mut cursor)?
||
self.unexpected_token(&mut cursor)?
)
&&
(
cursor == ""
||
self.unexpected_token(&mut cursor)?
)
&& { *s = cursor; true }
)
}
(These are incidentally in the order we wrote them.) We find this pattern much nicer than messing with else { false }
everywhere. We really do not like else { false }
and that's the only reason we use this, even if this is arguably an antipattern. We are wondering how others feel about it, and if maybe there's something that can be done at the language or maybe at the libs to help with this.