Crates.io | no_error |
lib.rs | no_error |
version | 0.0.2 |
source | src |
created_at | 2020-04-07 05:16:58.283248 |
updated_at | 2020-04-07 17:06:25.045649 |
description | an error library for no_std |
homepage | |
repository | https://github.com/richardanaya/no_error/ |
max_upload_size | |
id | 227166 |
size | 3,231 |
An error library for no_std
+ no_alloc
Rust
use no_error::*;
extern "C" {
fn print(x: const *u8);
}
const FAIL:ErrorCode = 42;
fn can_fail(i:i32) -> Result<()> {
if i < 0 {
// programmatically appends a "/0" to end of static string
error_message!("a failure happened","it happened in can_fail()")
} else if i == 0 {
// don't like c strings? supports failure codes too
error_code!(FAIL)
} else {
// you don't have to specify the source if you don't want
error_message!("a failure happened")
}
}
fn main() {
match can_fail() {
Ok(_) => (),
Err(a) => {
print(a.cstr_description());
print(a.cstr_source();
if let Some(c) = a.code() {
if c == FAIL {
print("secret of life".as_ptr());
}
}
},
};
}