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: NonZeroU8
Implementations
sourceimpl ScalarInt
impl ScalarInt
pub const TRUE: ScalarInt = _
pub const FALSE: ScalarInt = _
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
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
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>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl 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 Twhere
T: Copy,
impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for Twhere
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 Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<Ctxt, T> DepNodeParams<Ctxt> for Twhere
Ctxt: DepContext,
T: for<'a> HashStable<StableHashingContext<'a>> + Debug,
impl<Ctxt, T> DepNodeParams<Ctxt> for Twhere
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
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>
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 moresourceimpl<T, R> InternIteratorElement<T, R> for T
impl<T, R> InternIteratorElement<T, R> for T
type Output = R
fn intern_with<I, F>(iter: I, f: F) -> <T as InternIteratorElement<T, R>>::Outputwhere
I: Iterator<Item = T>,
F: FnOnce(&[T]) -> R,
sourceimpl<T> MaybeResult<T> for T
impl<T> MaybeResult<T> for T
sourceimpl<CTX, T> Value<CTX> for Twhere
CTX: DepContext,
impl<CTX, T> Value<CTX> for Twhere
CTX: DepContext,
default fn from_cycle_error(tcx: CTX) -> T
impl<'a, T> Captures<'a> for Twhere
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