Skip to content

Commit

Permalink
add another impl for from steelval for i64
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwparas committed Oct 30, 2023
1 parent ef77661 commit 11c124d
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion crates/steel-core/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,29 @@ impl IntoSteelVal for i64 {
}
}

impl FromSteelVal for i64 {
fn from_steelval(val: &SteelVal) -> crate::rvals::Result<Self> {
match val {
SteelVal::IntV(v) => (*v).try_into().map_err(|_err| {
SteelErr::new(
ErrorKind::ConversionError,
format!("Unable to convert i64 to isize: {}", v),
)
}),
SteelVal::BigNum(n) => n.as_ref().try_into().map_err(|_err| {
SteelErr::new(
ErrorKind::ConversionError,
format!("Unable to convert bignum to isize: {:?}", n),
)
}),
_ => Err(SteelErr::new(
ErrorKind::ConversionError,
format!("Unable to convert steelval to isize: {}", val),
)),
}
}
}

impl From<char> for SteelVal {
fn from(val: char) -> SteelVal {
SteelVal::CharV(val)
Expand Down Expand Up @@ -299,7 +322,7 @@ impl From<()> for SteelVal {
from_f64!(f64, f32);
from_for_isize!(i32, i16, i8, u8, u16, u32, u64, usize, isize);
try_from_impl!(NumV => f64, f32);
try_from_impl!(IntV => i64, i32, i16, i8, u8, u16, u32, u64, usize, isize);
try_from_impl!(IntV => i32, i16, i8, u8, u16, u32, u64, usize, isize);

impl TryFrom<SteelVal> for String {
type Error = SteelErr;
Expand Down

0 comments on commit 11c124d

Please sign in to comment.