#[macro_export]
macro_rules! attachment {
( $type:ident, $inner_type:ty $(,)? ) => {
#[doc = concat!(stringify!($type), ".")]
#[derive(Clone, Debug, Default, Hash)]
pub struct $type(pub $inner_type);
impl $type {
pub fn new<InnerT>(inner: InnerT) -> Self
where
InnerT: ::std::convert::Into<$inner_type>,
{
let inner: $inner_type = inner.into();
inner.into()
}
}
impl ::std::cmp::PartialEq for $type {
fn eq(&self, other: &Self) -> bool {
self.0.eq(&other.0)
}
}
impl ::std::cmp::Eq for $type {}
impl ::std::convert::From<$inner_type> for $type {
fn from(inner: $inner_type) -> Self {
Self(inner)
}
}
impl ::std::convert::Into<$inner_type> for $type {
fn into(self) -> $inner_type {
self.0
}
}
};
}
#[macro_export]
macro_rules! string_attachment {
( $type:ident $(,)? ) => {
#[doc = concat!(stringify!($type), ".")]
#[derive(Clone, Debug, Default, Hash)]
pub struct $type(pub ::std::string::String);
impl $type {
pub fn new<ToStringT>(inner: ToStringT) -> Self
where
ToStringT: ::std::string::ToString,
{
inner.to_string().into()
}
}
impl ::std::fmt::Display for $type {
fn fmt(&self, formatter: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
::std::fmt::Display::fmt(&self.0, formatter)
}
}
impl ::std::cmp::PartialEq for $type {
fn eq(&self, other: &Self) -> bool {
self.0.eq(&other.0)
}
}
impl ::std::cmp::Eq for $type {}
impl ::std::convert::From<::std::string::String> for $type {
fn from(inner: ::std::string::String) -> Self {
Self(inner)
}
}
impl ::std::convert::Into<::std::string::String> for $type {
fn into(self) -> ::std::string::String {
self.0
}
}
};
}
#[macro_export]
macro_rules! static_string_attachment {
( $type:ident $(,)? ) => {
#[doc = concat!(stringify!($type), ".")]
#[derive(Clone, Debug, Default, Hash)]
pub struct $type(pub &'static str);
impl $type {
pub fn new<IntoStringT>(inner: IntoStringT) -> Self
where
IntoStringT: ::std::convert::Into<&'static str>,
{
let inner: &'static str = inner.into();
inner.into()
}
}
impl ::std::fmt::Display for $type {
fn fmt(&self, formatter: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
::std::fmt::Display::fmt(&self.0, formatter)
}
}
impl ::std::cmp::PartialEq for $type {
fn eq(&self, other: &Self) -> bool {
self.0.eq(other.0)
}
}
impl ::std::cmp::Eq for $type {}
impl ::std::convert::From<&'static str> for $type {
fn from(inner: &'static str) -> Self {
Self(inner)
}
}
impl ::std::convert::Into<&'static str> for $type {
fn into(self) -> &'static str {
self.0
}
}
};
}
#[allow(unused_imports)]
pub use {attachment, static_string_attachment, string_attachment};