1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/// Enables contract runtime to panic with the given type. Any error type used in conjunction
/// with `#[handle_result]` has to implement this trait.
///
/// ```
/// use unc_sdk::FunctionError;
///
/// enum Error {
/// NotFound,
/// Unexpected { message: String },
/// }
///
/// impl FunctionError for Error {
/// fn panic(&self) -> ! {
/// match self {
/// Error::NotFound =>
/// unc_sdk::env::panic_str("not found"),
/// Error::Unexpected { message } =>
/// unc_sdk::env::panic_str(&format!("unexpected error: {}", message))
/// }
/// }
/// }
/// ```
/// A simple type used in conjunction with [FunctionError] representing that the function should
/// abort without a custom message.
///
/// ```
/// use unc_sdk::{Abort, unc};
///
/// #[unc(contract_state)]
/// #[derive(Default)]
/// pub struct Contract;
///
/// #[unc]
/// impl Contract {
/// #[handle_result]
/// pub fn foo(&self, text: &str) -> Result<String, Abort> {
/// if text == "success" {
/// Ok("success".to_string())
/// } else {
/// Err(Abort)
/// }
/// }
/// }
/// ```
;