I see that Anchor is suggesting the use of the require! macro, which produces code like this:
pub fn is_active(&self) -> bool {
self.state == GameState::Active
}
pub fn play(&mut self, tile: &Tile) -> Result<()> {
require!(self.is_active(), TicTacToeError::GameAlreadyOver);
...
}
However this is not idiomatic Rust. Normally in Rust you would see something like this:
fn is_active(&self) -> Result<()> {
match self.state.eq(&GameState::Active) {
false => Err(TicTacToeError::GameAlreadyOver),
true => Ok(()),
}
}
pub fn play(&mut self, tile: &Tile) -> Result<()> {
self.is_active()?;
...
}
I feel like this is an attempt to bring the Solidity coding style into Rust. Is there a technical reason to this, or is this popular just because a lot of smart contract devs are transitioning from Solidity to Rust?
I see that Anchor is suggesting the use of the
require!macro, which produces code like this:However this is not idiomatic Rust. Normally in Rust you would see something like this:
I feel like this is an attempt to bring the Solidity coding style into Rust. Is there a technical reason to this, or is this popular just because a lot of smart contract devs are transitioning from Solidity to Rust?