pub struct IntConv(/* private fields */);Expand description
The modifier byte of Inst::IntCast: source
type, destination type, and the overflow policy for values that do not
fit.
Layout: bits 0–2 source IntTy, bits 3–5 destination IntTy, bits
6–7 Overflow.
§Examples
use bytecode_lang::{IntConv, IntTy, Overflow};
let c = IntConv::new(IntTy::I64, IntTy::U8, Overflow::Wrap);
assert_eq!((c.from(), c.to(), c.overflow()), (IntTy::I64, IntTy::U8, Overflow::Wrap));
assert_eq!(c.to_string(), "i64.u8.wrap");
assert_eq!(IntConv::from_bits(c.bits()), Some(c));Implementations§
Source§impl IntConv
impl IntConv
Sourcepub const fn new(from: IntTy, to: IntTy, overflow: Overflow) -> Self
pub const fn new(from: IntTy, to: IntTy, overflow: Overflow) -> Self
A conversion from from to to under overflow.
§Examples
use bytecode_lang::{IntConv, IntTy, Overflow};
let c = IntConv::new(IntTy::U32, IntTy::I32, Overflow::Error);
assert_eq!(c.to_string(), "u32.i32");Sourcepub const fn from(self) -> IntTy
pub const fn from(self) -> IntTy
The source type.
§Examples
use bytecode_lang::{IntConv, IntTy, Overflow};
assert_eq!(IntConv::new(IntTy::I8, IntTy::I16, Overflow::Error).from(), IntTy::I8);Sourcepub const fn to(self) -> IntTy
pub const fn to(self) -> IntTy
The destination type.
§Examples
use bytecode_lang::{IntConv, IntTy, Overflow};
assert_eq!(IntConv::new(IntTy::I8, IntTy::I16, Overflow::Error).to(), IntTy::I16);Sourcepub const fn overflow(self) -> Overflow
pub const fn overflow(self) -> Overflow
The overflow policy.
§Examples
use bytecode_lang::{IntConv, IntTy, Overflow};
let c = IntConv::new(IntTy::I64, IntTy::I8, Overflow::Trap);
assert_eq!(c.overflow(), Overflow::Trap);Sourcepub const fn bits(self) -> u8
pub const fn bits(self) -> u8
The packed byte.
§Examples
use bytecode_lang::{IntConv, IntTy, Overflow};
assert_eq!(IntConv::new(IntTy::I8, IntTy::I8, Overflow::Error).bits(), 0);Sourcepub const fn from_bits(bits: u8) -> Option<Self>
pub const fn from_bits(bits: u8) -> Option<Self>
Unpacks the byte. Every byte names a conversion, so this returns
Some for all 256 values in format version 1. (promote decodes, but
int_cast always writes a statically typed register, so the builder
and the verifier refuse it.)
§Examples
use bytecode_lang::{IntConv, Overflow};
assert_eq!(IntConv::from_bits(0b1100_0000).map(|c| c.overflow()), Some(Overflow::Promote));Trait Implementations§
impl Copy for IntConv
impl Eq for IntConv
Source§impl Ord for IntConv
impl Ord for IntConv
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for IntConv
impl PartialOrd for IntConv
impl StructuralPartialEq for IntConv
Auto Trait Implementations§
impl Freeze for IntConv
impl RefUnwindSafe for IntConv
impl Send for IntConv
impl Sync for IntConv
impl Unpin for IntConv
impl UnsafeUnpin for IntConv
impl UnwindSafe for IntConv
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more