rust/src/helpers.rs

27 lines
792 B
Rust
Raw Normal View History

use super::{Scalar, ScalarMaybeUndef, EvalResult};
2018-05-01 11:13:22 -05:00
pub trait FalibleScalarExt {
/// HACK: this function just extracts all bits if `defined != 0`
/// Mainly used for args of C-functions and we should totally correctly fetch the size
/// of their arguments
fn to_bytes(self) -> EvalResult<'static, u128>;
}
impl<Tag> FalibleScalarExt for Scalar<Tag> {
fn to_bytes(self) -> EvalResult<'static, u128> {
match self {
Scalar::Bits { bits, size } => {
assert_ne!(size, 0);
Ok(bits)
},
Scalar::Ptr(_) => err!(ReadPointerAsBytes),
2018-07-10 10:32:38 -05:00
}
}
}
impl<Tag> FalibleScalarExt for ScalarMaybeUndef<Tag> {
fn to_bytes(self) -> EvalResult<'static, u128> {
self.not_undef()?.to_bytes()
}
}