Implement Into<ID> for all integer types.

This commit is contained in:
Sunli 2020-09-06 12:33:57 +08:00
parent c78aa8ffb5
commit dc02466cc7

View File

@ -42,14 +42,22 @@ impl Into<String> for ID {
}
}
impl TryFrom<ID> for usize {
type Error = ParseIntError;
macro_rules! try_from_integers {
($($ty:ty),*) => {
$(
impl TryFrom<ID> for $ty {
type Error = ParseIntError;
fn try_from(id: ID) -> std::result::Result<Self, Self::Error> {
id.0.parse()
}
fn try_from(id: ID) -> std::result::Result<Self, Self::Error> {
id.0.parse()
}
}
)*
};
}
try_from_integers!(i8, i16, i32, i64, u8, u16, u32, u64, isize, usize);
impl TryFrom<ID> for uuid::Uuid {
type Error = uuid::Error;