Skip to content

Commit

Permalink
Add impl From<_> for Object for more numeric types
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin authored and J-F-Liu committed Nov 4, 2017
1 parent 7604265 commit 1ec8f2a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,35 @@ impl From<i64> for Object {
}
}

macro_rules! from_smaller_ints {
($( $Int: ty )+) => {
$(
impl From<$Int> for Object {
fn from(number: $Int) -> Self {
Object::Integer(number as i64)
}
}
)+
}
}

from_smaller_ints! {
i8 i16 i32
u8 u16 u32
}

impl From<f64> for Object {
fn from(number: f64) -> Self {
Object::Real(number)
}
}

impl From<f32> for Object {
fn from(number: f32) -> Self {
Object::Real(number as f64)
}
}

impl From<String> for Object {
fn from(name: String) -> Self {
Object::Name(name.into_bytes())
Expand Down

0 comments on commit 1ec8f2a

Please sign in to comment.