-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Have
#[handle_result]
support any Result
type
- Loading branch information
Showing
8 changed files
with
51 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use borsh::{BorshDeserialize, BorshSerialize}; | ||
use near_sdk::near_bindgen; | ||
|
||
type MyResult = Result<u32, &'static str>; | ||
|
||
#[near_bindgen] | ||
#[derive(Default, BorshDeserialize, BorshSerialize)] | ||
struct Contract { | ||
value: u32, | ||
} | ||
|
||
#[near_bindgen] | ||
impl Contract { | ||
#[handle_result] | ||
pub fn fun(&self) -> MyResult { | ||
Err("error") | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
pub trait ResultTypeExt: seal::ResultTypeExtSeal { | ||
type Okay; | ||
type Error; | ||
} | ||
|
||
impl<T, E> ResultTypeExt for Result<T, E> { | ||
type Okay = T; | ||
type Error = E; | ||
} | ||
|
||
// This is the "sealed trait" pattern: | ||
// https://rust-lang.github.io/api-guidelines/future-proofing.html | ||
mod seal { | ||
pub trait ResultTypeExtSeal {} | ||
|
||
impl<T, E> ResultTypeExtSeal for Result<T, E> {} | ||
} |