Macro type_str

Source
macro_rules! type_str {
    ($vis: vis $name: ident = $value: expr $(=> $doc: expr)?) => { ... };
}
Expand description

Lifts static strings to type-level strings.

ยงExamples

use refinement_types::type_str;

type_str!(HelloWorld = "Hello, world!");

Is equivalent to:

use core::fmt;

use refinement_types::{StaticStr, TypeStr};

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
struct HelloWorld;

impl TypeStr for HelloWorld {
    const VALUE: StaticStr = "Hello, world!";
}

impl fmt::Display for HelloWorld {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter.write_str(Self::VALUE)
    }
}