Skip to content

Commit

Permalink
impl From all primitive int types for Token
Browse files Browse the repository at this point in the history
  • Loading branch information
chanced committed Jul 9, 2024
1 parent 91cadb4 commit daacdd6
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,23 +271,18 @@ impl<'de> serde::Deserialize<'de> for Token<'de> {
}
}

impl From<usize> for Token<'static> {
fn from(v: usize) -> Self {
Token::from_encoded_unchecked(v.to_string())
}
}

impl From<u32> for Token<'static> {
fn from(v: u32) -> Self {
Token::from_encoded_unchecked(v.to_string())
}
}

impl From<u64> for Token<'static> {
fn from(v: u64) -> Self {
Token::from_encoded_unchecked(v.to_string())
}
macro_rules! impl_from_num {
($($ty:ty),*) => {
$(
impl From<$ty> for Token<'static> {
fn from(v: $ty) -> Self {
Token::from_encoded_unchecked(v.to_string())
}
}
)*
};
}
impl_from_num!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);

impl<'a> From<&'a str> for Token<'a> {
fn from(value: &'a str) -> Self {
Expand Down

0 comments on commit daacdd6

Please sign in to comment.