From 857d5167dfa13054dd0d21d3d54f8147eea0d546 Mon Sep 17 00:00:00 2001 From: asonix Date: Fri, 17 Jul 2020 08:14:23 -0500 Subject: [PATCH] Impl display for kinds --- src/macros.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/macros.rs b/src/macros.rs index 92955e9..5af70aa 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -39,6 +39,12 @@ macro_rules! kind { $y, } + impl std::fmt::Display for $x { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, stringify!($y)) + } + } + impl Default for $x { fn default() -> Self { $x::$y @@ -67,3 +73,13 @@ macro_rules! uri { $x.parse::()? }}; } + +#[cfg(test)] +mod tests { + #[test] + fn to_string_works() { + kind!(MyType, My); + + assert_eq!(MyType::My.to_string(), "My") + } +}