pub trait LiftedString {
const VALUE: &'static str;
}
#[macro_export]
macro_rules! typestring {
(
$(
$(# $attr:tt)*
$vis:vis type $name:ident = $val:literal ;
)*
) => {
$(
$(# $attr)*
#[derive(Default)]
$vis struct $name ;
impl $crate::LiftedString for $name {
const VALUE: &'static str = $val;
}
)*
};
}
mod test {
use super::*;
typestring! {
type Foo = "foo";
#[derive(Debug)]
type Bar = "bar";
}
#[test]
fn test_values_are_correct() {
assert_eq!(Foo::VALUE, "foo");
assert_eq!(Bar::VALUE, "bar");
}
}