stack_cstr/
macros.rs

1#[macro_export]
2macro_rules! cstr {
3    ([$($size:expr),*], $($args:tt)*) => {{
4        let args = format_args!($($args)*);
5
6        let result: Box<dyn $crate::CStrLike> = if false { unreachable!() }
7        $(
8            else if let Ok(s) = $crate::CStrStack::<$size>::new(args) {
9                Box::new(s)
10            }
11        )*
12        else {
13            Box::new($crate::CStrHeap::new(std::ffi::CString::new(format!($($args)*)).unwrap()))
14        };
15
16        result
17    }};
18    ($($args:tt)*) => {
19        cstr!([32, 128], $($args)*)
20    };
21}