identifiers: Add more conversion methods and a trait impl

This commit is contained in:
Jonas Platte 2021-04-05 21:41:54 +02:00
parent d883debe07
commit 0dcbec5fa7
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67

View File

@ -92,11 +92,31 @@ macro_rules! common_impls {
self.full_id.as_bytes()
}
}
doc_concat! {
#[doc = concat!("Converts this `", stringify!($id), "` into a `String`")]
pub fn into_string(self) -> String {
self.full_id.into()
}
}
doc_concat! {
#[doc = concat!("Converts this `", stringify!($id), "` into a `Vec<u8>`")]
pub fn into_bytes(self) -> Vec<u8> {
Box::<[u8]>::from(self.full_id).into()
}
}
}
impl ::std::convert::From<$id> for ::std::string::String {
fn from(id: $id) -> Self {
id.full_id.into()
id.into_string()
}
}
impl ::std::convert::From<$id> for ::std::vec::Vec<u8> {
fn from(id: $id) -> Self {
id.into_bytes()
}
}