mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-11 04:16:55 +00:00
31 lines
593 B
Rust
31 lines
593 B
Rust
|
|
// Default methods for string keys.
|
|
macro_rules! impl_string_key {
|
|
($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)
|
|
}
|
|
}
|
|
}
|
|
}
|