File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 5353 toolchain : ${{ env.RUST_TOOLCHAIN }}
5454 components : rustfmt, clippy
5555 - uses : Swatinem/rust-cache@v1
56- - run : cargo test --lib
56+ - run : cargo test
5757
5858 doc :
5959 runs-on : ubuntu-latest
Original file line number Diff line number Diff line change @@ -103,7 +103,21 @@ macro_rules! assert_owner {
103103 } ;
104104}
105105
106- /// Ensures an [Option] can be unwrapped, otherwise returns the error
106+ /// Ensures an [Option] can be unwrapped, otherwise returns the error.
107+ ///
108+ /// # Example
109+ ///
110+ /// ```should_panic
111+ /// # use anchor_lang::prelude::*;
112+ /// # impl From<ErrorCode> for ProgramError { fn from(code: ErrorCode) -> Self { ProgramError::Custom(10) } }
113+ /// # pub enum ErrorCode { MyError }
114+ /// # #[macro_use] extern crate vipers; fn main() -> ProgramResult {
115+ /// let one = 1_u64;
116+ /// let two = 2_u64;
117+ /// let my_value = unwrap_or_err!(one.checked_sub(2), MyError); // throws an error
118+ /// Ok(())
119+ /// # }
120+ /// ```
107121#[ macro_export]
108122macro_rules! unwrap_or_err {
109123 ( $option: expr, $error: tt $( , ) ?) => {
You can’t perform that action at this time.
0 commit comments