Expand description
The raw bytes of a simple value.
This is a packed struct in order to allow this type to be optimally embedded in enums (like Scalar).
Fields
data: u128
The first size
bytes of data
are the value.
Do not try to read less or more bytes than that. The remaining bytes must be 0.
size: u8
Implementations
sourceimpl ScalarInt
impl ScalarInt
pub const TRUE: ScalarInt = ScalarInt { data: 1_u128, size: 1 }
pub const FALSE: ScalarInt = ScalarInt { data: 0_u128, size: 1 }
pub const ZST: ScalarInt = ScalarInt { data: 0_u128, size: 0 }
pub fn size(self) -> Size
sourcefn check_data(self)
fn check_data(self)
Make sure the data
fits in size
.
This is guaranteed by all constructors here, but having had this check saved us from
bugs many times in the past, so keeping it around is definitely worth it.
pub fn null(size: Size) -> Self
pub fn is_null(self) -> bool
pub fn try_from_uint(i: impl Into<u128>, size: Size) -> Option<Self>
pub fn try_from_int(i: impl Into<i128>, size: Size) -> Option<Self>
pub fn assert_bits(self, target_size: Size) -> u128
pub fn to_bits(self, target_size: Size) -> Result<u128, Size>
pub fn try_to_machine_usize<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Result<u64, Size>
sourcepub fn try_to_uint(self, size: Size) -> Result<u128, Size>
pub fn try_to_uint(self, size: Size) -> Result<u128, Size>
Tries to convert the ScalarInt
to an unsigned integer of the given size.
Fails if the size of the ScalarInt
is unequal to size
and returns the
ScalarInt
s size in that case.
pub fn try_to_u8(self) -> Result<u8, Size>
sourcepub fn try_to_u16(self) -> Result<u16, Size>
pub fn try_to_u16(self) -> Result<u16, Size>
Tries to convert the ScalarInt
to u16
. Fails if the size of the ScalarInt
in not equal to Size { raw: 2 }
and returns the size
value of the ScalarInt
in
that case.
sourcepub fn try_to_u32(self) -> Result<u32, Size>
pub fn try_to_u32(self) -> Result<u32, Size>
Tries to convert the ScalarInt
to u32
. Fails if the size
of the ScalarInt
in not equal to Size { raw: 4 }
and returns the size
value of the ScalarInt
in
that case.
sourcepub fn try_to_u64(self) -> Result<u64, Size>
pub fn try_to_u64(self) -> Result<u64, Size>
Tries to convert the ScalarInt
to u64
. Fails if the size
of the ScalarInt
in not equal to Size { raw: 8 }
and returns the size
value of the ScalarInt
in
that case.
sourcepub fn try_to_u128(self) -> Result<u128, Size>
pub fn try_to_u128(self) -> Result<u128, Size>
Tries to convert the ScalarInt
to u128
. Fails if the size
of the ScalarInt
in not equal to Size { raw: 16 }
and returns the size
value of the ScalarInt
in
that case.
sourcepub fn try_to_int(self, size: Size) -> Result<i128, Size>
pub fn try_to_int(self, size: Size) -> Result<i128, Size>
Tries to convert the ScalarInt
to a signed integer of the given size.
Fails if the size of the ScalarInt
is unequal to size
and returns the
ScalarInt
s size in that case.
sourcepub fn try_to_i8(self) -> Result<i8, Size>
pub fn try_to_i8(self) -> Result<i8, Size>
Tries to convert the ScalarInt
to i8.
Fails if the size of the ScalarInt
is unequal to Size { raw: 1 }
and returns the ScalarInt
s size in that case.
sourcepub fn try_to_i16(self) -> Result<i16, Size>
pub fn try_to_i16(self) -> Result<i16, Size>
Tries to convert the ScalarInt
to i16.
Fails if the size of the ScalarInt
is unequal to Size { raw: 2 }
and returns the ScalarInt
s size in that case.
sourcepub fn try_to_i32(self) -> Result<i32, Size>
pub fn try_to_i32(self) -> Result<i32, Size>
Tries to convert the ScalarInt
to i32.
Fails if the size of the ScalarInt
is unequal to Size { raw: 4 }
and returns the ScalarInt
s size in that case.
sourcepub fn try_to_i64(self) -> Result<i64, Size>
pub fn try_to_i64(self) -> Result<i64, Size>
Tries to convert the ScalarInt
to i64.
Fails if the size of the ScalarInt
is unequal to Size { raw: 8 }
and returns the ScalarInt
s size in that case.
sourcepub fn try_to_i128(self) -> Result<i128, Size>
pub fn try_to_i128(self) -> Result<i128, Size>
Tries to convert the ScalarInt
to i128.
Fails if the size of the ScalarInt
is unequal to Size { raw: 16 }
and returns the ScalarInt
s size in that case.
Trait Implementations
sourceimpl<CTX> HashStable<CTX> for ScalarInt
impl<CTX> HashStable<CTX> for ScalarInt
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher)
sourceimpl Ord for ScalarInt
impl Ord for ScalarInt
sourceimpl PartialOrd<ScalarInt> for ScalarInt
impl PartialOrd<ScalarInt> for ScalarInt
sourcefn partial_cmp(&self, other: &ScalarInt) -> Option<Ordering>
fn partial_cmp(&self, other: &ScalarInt) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Copy for ScalarInt
impl Eq for ScalarInt
impl StructuralEq for ScalarInt
impl StructuralPartialEq for ScalarInt
Auto Trait Implementations
impl RefUnwindSafe for ScalarInt
impl Send for ScalarInt
impl Sync for ScalarInt
impl Unpin for ScalarInt
impl UnwindSafe for ScalarInt
Blanket Implementations
sourceimpl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for T where
T: Copy,
impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for T where
T: Copy,
fn allocate_on(self, arena: &'a Arena<'tcx>) -> &'a mut T
fn allocate_from_iter(
arena: &'a Arena<'tcx>,
iter: impl IntoIterator<Item = T>
) -> &'a mut [T]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Ctxt, T> DepNodeParams<Ctxt> for T where
Ctxt: DepContext,
T: for<'a> HashStable<StableHashingContext<'a>> + Debug,
impl<Ctxt, T> DepNodeParams<Ctxt> for T where
Ctxt: DepContext,
T: for<'a> HashStable<StableHashingContext<'a>> + Debug,
default fn fingerprint_style() -> FingerprintStyle
sourcedefault fn to_fingerprint(&self, tcx: Ctxt) -> Fingerprint
default fn to_fingerprint(&self, tcx: Ctxt) -> Fingerprint
This method turns the parameters of a DepNodeConstructor into an opaque Fingerprint to be used in DepNode. Not all DepNodeParams support being turned into a Fingerprint (they don’t need to if the corresponding DepNode is anonymous). Read more
default fn to_debug_str(&self, Ctxt) -> String
sourcedefault fn recover(Ctxt, &DepNode<<Ctxt as DepContext>::DepKind>) -> Option<T>
default fn recover(Ctxt, &DepNode<<Ctxt as DepContext>::DepKind>) -> Option<T>
This method tries to recover the query key from the given DepNode
,
something which is needed when forcing DepNode
s during red-green
evaluation. The query system will only call this method if
fingerprint_style()
is not FingerprintStyle::Opaque
.
It is always valid to return None
here, in which case incremental
compilation will treat the query as having changed instead of forcing it. Read more
sourceimpl<T> MaybeResult<T> for T
impl<T> MaybeResult<T> for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<'a, T> Captures<'a> for T where
T: ?Sized,
Layout
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.
Size: 17 bytes