identifiers: Clean up internal macros
This commit is contained in:
parent
f448f6756e
commit
a81769c3fd
@ -24,32 +24,6 @@ macro_rules! partial_eq_string {
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! as_str_based_impls {
|
||||
($id:ty) => {
|
||||
impl AsRef<str> for $id {
|
||||
fn as_ref(&self) -> &str {
|
||||
self.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for $id {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl serde::Serialize for $id {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_str(self.as_str())
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! opaque_identifier_common_impls {
|
||||
($id:ty) => {
|
||||
impl $id {
|
||||
@ -80,12 +54,6 @@ macro_rules! opaque_identifier_common_impls {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for $id {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
<str as std::fmt::Debug>::fmt(self.as_str(), f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Box<$id> {
|
||||
fn clone(&self) -> Self {
|
||||
(**self).to_owned()
|
||||
@ -100,9 +68,9 @@ macro_rules! opaque_identifier_common_impls {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&$id> for Box<$id> {
|
||||
fn from(id: &$id) -> Self {
|
||||
id.to_owned()
|
||||
impl AsRef<str> for $id {
|
||||
fn as_ref(&self) -> &str {
|
||||
self.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,6 +80,12 @@ macro_rules! opaque_identifier_common_impls {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&$id> for Box<$id> {
|
||||
fn from(id: &$id) -> Self {
|
||||
id.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&$id> for std::rc::Rc<$id> {
|
||||
fn from(s: &$id) -> std::rc::Rc<$id> {
|
||||
let rc = std::rc::Rc::<str>::from(s.as_str());
|
||||
@ -150,7 +124,28 @@ macro_rules! opaque_identifier_common_impls {
|
||||
}
|
||||
}
|
||||
|
||||
as_str_based_impls!($id);
|
||||
impl std::fmt::Debug for $id {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
<str as std::fmt::Debug>::fmt(self.as_str(), f)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for $id {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl serde::Serialize for $id {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_str(self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
partial_eq_string!($id);
|
||||
partial_eq_string!(Box<$id>);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user