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§
source§impl 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_bool(self) -> Result<bool, Size>
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§
source§impl<CTX> HashStable<CTX> for ScalarInt
impl<CTX> HashStable<CTX> for ScalarInt
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher)
source§impl Ord for ScalarInt
impl Ord for ScalarInt
source§impl PartialOrd<ScalarInt> for ScalarInt
impl PartialOrd<ScalarInt> for ScalarInt
1.0.0 · source§fn 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§
source§impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for Twhere
T: Copy,
impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for Twhere
T: Copy,
fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut T
fn allocate_from_iter<'a>(
arena: &'a Arena<'tcx>,
iter: impl IntoIterator<Item = T>
) -> &'a mut [T] ⓘ
source§impl<Tcx, T> DepNodeParams<Tcx> for Twhere
Tcx: DepContext,
T: for<'a> HashStable<StableHashingContext<'a>> + Debug,
impl<Tcx, T> DepNodeParams<Tcx> for Twhere
Tcx: DepContext,
T: for<'a> HashStable<StableHashingContext<'a>> + Debug,
default fn fingerprint_style() -> FingerprintStyle
source§default fn to_fingerprint(&self, tcx: Tcx) -> Fingerprint
default fn to_fingerprint(&self, tcx: Tcx) -> Fingerprint
default fn to_debug_str(&self, _: Tcx) -> String
source§default fn recover(
_: Tcx,
_: &DepNode<<Tcx as DepContext>::DepKind>
) -> Option<T>
default fn recover(
_: Tcx,
_: &DepNode<<Tcx 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 moresource§impl<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,
source§impl<T> MaybeResult<T> for T
impl<T> MaybeResult<T> for T
source§impl<'tcx, T> ToPredicate<'tcx, T> for T
impl<'tcx, T> ToPredicate<'tcx, T> for T
fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> T
source§impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
default fn from_cycle_error(tcx: Tcx, _: &[QueryInfo]) -> T
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