1#[macro_export]
6macro_rules! tinystr {
7 ($n:literal, $s:literal) => {{
8 const TINYSTR_MACRO_CONST: $crate::TinyAsciiStr<$n> = {
10 match $crate::TinyAsciiStr::try_from_utf8($s.as_bytes()) {
11 Ok(s) => s,
12 Err(_) => panic!(concat!("Failed to construct tinystr from ", $s)),
14 }
15 };
16 TINYSTR_MACRO_CONST
17 }};
18}
19
20#[cfg(test)]
21mod tests {
22 #[test]
23 fn test_macro_construction() {
24 let s1 = tinystr!(8, "foobar");
25 assert_eq!(&*s1, "foobar");
26
27 let s1 = tinystr!(12, "foobarbaz");
28 assert_eq!(&*s1, "foobarbaz");
29 }
30}