concordium-rust-smart-contracts icon indicating copy to clipboard operation
concordium-rust-smart-contracts copied to clipboard

In concordium-std, let user specify enum variant to be used as Default error

Open abizjak opened this issue 4 years ago • 0 comments

A user can now write the following code:

#[derive(Reject)]
enum MyReceiveError {
  MyErrorVariant,
  ...
}

fn receive(...) -> Result<A, MyReceiveError> {
  ...
}

We would like to be able to call bail from receive functions that use custom error types. But for that, we need to provide a Default implementation for errors.

This task is to allow the user to write

#[derive(Reject)]
enum MyReceiveError {
  #[default]
  MyErrorVariant,
  ...
}

which will generate a Default implementation

impl Default for MyReceiveError {
  fn default() -> Self {
    MyReceiveError::MyErrorVariant
  }
}

abizjak avatar Jul 09 '21 14:07 abizjak