From 9757befc7b0228bbda616bf1750c392fe24783dc Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sun, 24 Mar 2024 18:38:55 -0400 Subject: [PATCH] move tokens' macros into module --- crates/_types/tokens/src/lib.rs | 2 +- .../impl_crockford_generator.rs} | 30 ------------------- .../tokens/src/macros/impl_string_token.rs | 30 +++++++++++++++++++ crates/_types/tokens/src/macros/mod.rs | 2 ++ 4 files changed, 33 insertions(+), 31 deletions(-) rename crates/_types/tokens/src/{macros.rs => macros/impl_crockford_generator.rs} (90%) create mode 100644 crates/_types/tokens/src/macros/impl_string_token.rs create mode 100644 crates/_types/tokens/src/macros/mod.rs diff --git a/crates/_types/tokens/src/lib.rs b/crates/_types/tokens/src/lib.rs index 2ed1809949..37cc054cc6 100644 --- a/crates/_types/tokens/src/lib.rs +++ b/crates/_types/tokens/src/lib.rs @@ -48,7 +48,7 @@ pub(crate) enum TokenCharacterSet { pub(crate) static MINIMUM_CHARACTER_ENTROPY : usize = 8; #[macro_use] -mod macros; +pub (crate) mod macros; pub (crate) mod deterministic_rng; pub (crate) mod prefixes; diff --git a/crates/_types/tokens/src/macros.rs b/crates/_types/tokens/src/macros/impl_crockford_generator.rs similarity index 90% rename from crates/_types/tokens/src/macros.rs rename to crates/_types/tokens/src/macros/impl_crockford_generator.rs index 44fc14d6df..ee30b68f8c 100644 --- a/crates/_types/tokens/src/macros.rs +++ b/crates/_types/tokens/src/macros/impl_crockford_generator.rs @@ -1,34 +1,4 @@ -// Default methods for string wrapper types. -macro_rules! impl_string_token { - ($t:ident) => { - // Constructors and accessors. - impl $t { - #[inline] - pub fn new(value: String) -> Self { - $t(value) - } - - #[inline] - pub fn new_from_str(value: &str) -> Self { - $t(value.to_string()) - } - - #[inline] - pub fn as_str(&self) -> &str { - &self.0 - } - } - - // Display trait. - impl std::fmt::Display for $t { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.0) - } - } - } -} - // TODO(bt, 2023-11-01): Don't generate slurs or dangerous terms in the token generator // see: https://news.ycombinator.com/item?id=35337210 // see: https://www.reddit.com/r/ProgrammerHumor/comments/3ov56n/randomly_generating_ids_can_be_dangerous/ diff --git a/crates/_types/tokens/src/macros/impl_string_token.rs b/crates/_types/tokens/src/macros/impl_string_token.rs new file mode 100644 index 0000000000..e082e567d8 --- /dev/null +++ b/crates/_types/tokens/src/macros/impl_string_token.rs @@ -0,0 +1,30 @@ + +// Default methods for string wrapper types. +macro_rules! impl_string_token { + ($t:ident) => { + // Constructors and accessors. + impl $t { + #[inline] + pub fn new(value: String) -> Self { + $t(value) + } + + #[inline] + pub fn new_from_str(value: &str) -> Self { + $t(value.to_string()) + } + + #[inline] + pub fn as_str(&self) -> &str { + &self.0 + } + } + + // Display trait. + impl std::fmt::Display for $t { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0) + } + } + } +} diff --git a/crates/_types/tokens/src/macros/mod.rs b/crates/_types/tokens/src/macros/mod.rs new file mode 100644 index 0000000000..21dea065a8 --- /dev/null +++ b/crates/_types/tokens/src/macros/mod.rs @@ -0,0 +1,2 @@ +#[macro_use] pub (crate) mod impl_string_token; +#[macro_use] pub (crate) mod impl_crockford_generator;