custom_try/
_lib.rs

1#![doc = include_str!("../README.md")]
2#![no_std]
3#![forbid(unsafe_code)]
4
5#[allow(unused)]
6use {
7    ::core::{
8        ops::Not as _,
9    },
10};
11
12#[cfg(COMMENTED_OUT)] // <- Remove this when used!
13/// The crate's prelude.
14pub
15mod prelude {
16    // …
17}
18
19/// Replace `expr?` occurrences in the decorated item with `r#try!( expr )`.
20///
21/// The `r#try!` default path can be overridden by giving it as an argument
22/// to the attribute macro:
23///
24/// ## Examples
25///
26/// ### 1. For FFI
27///
28/**  - ```rust
29    use ::custom_try::custom_try;
30
31    #[repr(transparent)]
32    pub struct FfiResult {
33        pub status_code: ::std::os::raw::c_int,
34    }
35
36    impl FfiResult {
37        pub const OK: Self = Self { status_code: 0 };
38        pub const ERR: Self = Self { status_code: -1 };
39    }
40
41    macro_rules! unwrap_option {( $option:expr $(,)? ) => (
42        match $option {
43            Some(thing) => thing,
44            None => return $crate::FfiResult::ERR,
45        }
46    )}
47
48    #[custom_try(unwrap_option!)]
49    extern "C" fn ffi_function() -> FfiResult {
50        let x = the_answer_to_life_the_universe_and_everything()?;
51        println!("{}", x);
52        FfiResult::OK
53    }
54
55    /// If you only have one case of `?` semantics, you can default to that one
56    /// using the default `r#try!` macro name.
57    use unwrap_option as r#try;
58
59    #[custom_try]
60    extern "C" fn ffi_function2() -> FfiResult {
61        let x = the_answer_to_life_the_universe_and_everything()?;
62        println!("{}", x);
63        FfiResult::OK
64    }
65    #
66    # fn main() {}
67    # fn the_answer_to_life_the_universe_and_everything() -> Option<i32> { None }
68    ``` */
69pub use ::custom_try_proc_macros::custom_try;
70
71// macro internals
72#[doc(hidden)] /** Not part of the public API */ pub
73mod ඞ {
74    pub use ::core; // or `std`
75}
76
77#[doc = include_str!("compile_fail_tests.md")]
78mod _compile_fail_tests {}