mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-06 02:00:46 +00:00
move tokens' macros into module
This commit is contained in:
1 parent
80b572e5ee
commit
9757befc7b
4 files changed
+33
-31
No files matched your search
@@ -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;
|
||||
|
||||
-30
@@ -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/
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
#[macro_use] pub (crate) mod impl_string_token;
|
||||
#[macro_use] pub (crate) mod impl_crockford_generator;
|
||||
Reference in new issue
Block a user