Reputation: 79
I currently have a match statement in the form of
match ball.side {
Side::Left => x(),
Side::Right => y(),
}
But what I would need is something along the lines of
match ball.side {
Side::Left => x(),a(),
Side::Right => y(), b(),
}
And of course this does not compile, but how could I make this kind of sequence work? I know I could also just work with an if-statement but I am curious how this can exactly be solved with match.
Upvotes: 0
Views: 3510
Reputation: 30051
A sequence of statements in a block:
match ball.side {
Side::Left => {
x();
a();
}
Side::Right => {
y();
b();
}
}
Note that the right side of a match
arm must be an expression, and that blocks are expressions (which can produce a value) in Rust.
Upvotes: 11