macro_rules! new_type {
(
$(#[$attr:meta])*
$name:ident(
$(#[$type_attr:meta])*
$type:ty
)
) => { ... };
(
$(#[$attr:meta])*
$name:ident(
$(#[$type_attr:meta])*
$type:ty
)
impl {
$($item:tt)*
}
) => { ... };
(
@new_type $(#[$attr:meta])*,
$name:ident(
$(#[$type_attr:meta])*
$type:ty
),
$new_doc:expr,
impl {
$($item:tt)*
}
) => { ... };
}Expand description
Creates a newtype with following code automatically generated:
- Derives
Clone,Debug,PartialEq,Eq,PartialOrd,Ord, andDisplay. - Implements
new,Deref, andFrom. - Allows one to implement additional traits and features as needed.
This was copied from the oauth2-rs crate.
ยงExamples
new_type! [
/// A safe wrapper around a `user_id` string
#[derive(Eq, Hash)]
UserId(String)
impl {
fn as_str(&self) -> &str {
&self
}
}
];