Skip to content

Commit f97538f

Browse files
committed
more doctest
1 parent c2e9a09 commit f97538f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
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

src/assert.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff 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]
108122
macro_rules! unwrap_or_err {
109123
($option:expr, $error:tt $(,)?) => {

0 commit comments

Comments
 (0)