From dc02466cc7b5561a0a58524af7c97c3750806652 Mon Sep 17 00:00:00 2001 From: Sunli Date: Sun, 6 Sep 2020 12:33:57 +0800 Subject: [PATCH] Implement Into for all integer types. --- src/scalars/id.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/scalars/id.rs b/src/scalars/id.rs index e70c9a98..038e796f 100644 --- a/src/scalars/id.rs +++ b/src/scalars/id.rs @@ -42,14 +42,22 @@ impl Into for ID { } } -impl TryFrom for usize { - type Error = ParseIntError; +macro_rules! try_from_integers { + ($($ty:ty),*) => { + $( + impl TryFrom for $ty { + type Error = ParseIntError; - fn try_from(id: ID) -> std::result::Result { - id.0.parse() - } + fn try_from(id: ID) -> std::result::Result { + id.0.parse() + } + } + )* + }; } +try_from_integers!(i8, i16, i32, i64, u8, u16, u32, u64, isize, usize); + impl TryFrom for uuid::Uuid { type Error = uuid::Error;