#[repr(packed(1))]pub struct ScalarInt {
data: u128,
size: NonZero<u8>,
}
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: NonZero<u8>
Implementations§
Source§impl ScalarInt
impl ScalarInt
pub const TRUE: ScalarInt = _
pub const FALSE: ScalarInt = _
fn raw(data: u128, size: Size) -> Self
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>
Sourcepub fn truncate_from_uint(i: impl Into<u128>, size: Size) -> (Self, bool)
pub fn truncate_from_uint(i: impl Into<u128>, size: Size) -> (Self, bool)
Returns the truncated result, and whether truncation changed the value.
pub fn try_from_int(i: impl Into<i128>, size: Size) -> Option<Self>
Sourcepub fn truncate_from_int(i: impl Into<i128>, size: Size) -> (Self, bool)
pub fn truncate_from_int(i: impl Into<i128>, size: Size) -> (Self, bool)
Returns the truncated result, and whether truncation changed the value.
pub fn try_from_target_usize( i: impl Into<u128>, tcx: TyCtxt<'_>, ) -> Option<Self>
Sourcepub fn try_to_bits(self, target_size: Size) -> Result<u128, Size>
pub fn try_to_bits(self, target_size: Size) -> Result<u128, Size>
Try to convert this ScalarInt to the raw underlying bits.
Fails if the size is wrong. Generally a wrong size should lead to a panic,
but Miri sometimes wants to be resilient to size mismatches,
so the interpreter will generally use this try
method.
pub fn to_bits(self, target_size: Size) -> u128
Sourcepub fn to_bits_unchecked(self) -> u128
pub fn to_bits_unchecked(self) -> u128
Extracts the bits from the scalar without checking the size.
Sourcepub fn to_uint(self, size: Size) -> u128
pub fn to_uint(self, size: Size) -> u128
Converts the ScalarInt
to an unsigned integer of the given size.
Panics if the size of the ScalarInt
is not equal to size
.
Sourcepub fn to_u8(self) -> u8
pub fn to_u8(self) -> u8
Converts the ScalarInt
to u8
.
Panics if the size
of the ScalarInt
in not equal to 1 byte.
Sourcepub fn to_u16(self) -> u16
pub fn to_u16(self) -> u16
Converts the ScalarInt
to u16
.
Panics if the size of the ScalarInt
in not equal to 2 bytes.
Sourcepub fn to_u32(self) -> u32
pub fn to_u32(self) -> u32
Converts the ScalarInt
to u32
.
Panics if the size
of the ScalarInt
in not equal to 4 bytes.
Sourcepub fn to_u64(self) -> u64
pub fn to_u64(self) -> u64
Converts the ScalarInt
to u64
.
Panics if the size
of the ScalarInt
in not equal to 8 bytes.
Sourcepub fn to_u128(self) -> u128
pub fn to_u128(self) -> u128
Converts the ScalarInt
to u128
.
Panics if the size
of the ScalarInt
in not equal to 16 bytes.
pub fn to_target_usize(&self, tcx: TyCtxt<'_>) -> u64
Sourcepub fn try_to_bool(self) -> Result<bool, ()>
pub fn try_to_bool(self) -> Result<bool, ()>
Converts the ScalarInt
to bool
.
Panics if the size
of the ScalarInt
is not equal to 1 byte.
Errors if it is not a valid bool
.
Sourcepub fn to_int(self, size: Size) -> i128
pub fn to_int(self, size: Size) -> i128
Converts the ScalarInt
to a signed integer of the given size.
Panics if the size of the ScalarInt
is not equal to size
.
Sourcepub fn to_i8(self) -> i8
pub fn to_i8(self) -> i8
Converts the ScalarInt
to i8.
Panics if the size of the ScalarInt
is not equal to 1 byte.
Sourcepub fn to_i16(self) -> i16
pub fn to_i16(self) -> i16
Converts the ScalarInt
to i16.
Panics if the size of the ScalarInt
is not equal to 2 bytes.
Sourcepub fn to_i32(self) -> i32
pub fn to_i32(self) -> i32
Converts the ScalarInt
to i32.
Panics if the size of the ScalarInt
is not equal to 4 bytes.
Sourcepub fn to_i64(self) -> i64
pub fn to_i64(self) -> i64
Converts the ScalarInt
to i64.
Panics if the size of the ScalarInt
is not equal to 8 bytes.
Sourcepub fn to_i128(self) -> i128
pub fn to_i128(self) -> i128
Converts the ScalarInt
to i128.
Panics if the size of the ScalarInt
is not equal to 16 bytes.
pub fn to_target_isize(&self, tcx: TyCtxt<'_>) -> i64
pub fn to_float<F: Float>(self) -> F
pub fn to_f16(self) -> Half
pub fn to_f32(self) -> Single
pub fn to_f64(self) -> Double
pub fn to_f128(self) -> Quad
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)
impl Copy for ScalarInt
impl Eq for ScalarInt
impl StructuralPartialEq for ScalarInt
Auto Trait Implementations§
impl DynSend for ScalarInt
impl DynSync for ScalarInt
impl Freeze for ScalarInt
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(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut T
fn allocate_from_iter( arena: &'tcx Arena<'tcx>, iter: impl IntoIterator<Item = T>, ) -> &'tcx mut [T]
Source§impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for Twhere
T: Copy,
impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for Twhere
T: Copy,
fn allocate_on(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut T
fn allocate_from_iter( arena: &'tcx Arena<'tcx>, iter: impl IntoIterator<Item = T>, ) -> &'tcx mut [T]
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
Source§impl<Tcx, T> DepNodeParams<Tcx> for T
impl<Tcx, T> DepNodeParams<Tcx> for T
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) -> Option<T>
default fn recover(_: Tcx, _: &DepNode) -> 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.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> Filterable for T
impl<T> Filterable for T
Source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<P> IntoQueryParam<P> for P
impl<P> IntoQueryParam<P> for P
fn into_query_param(self) -> P
Source§impl<T> MaybeResult<T> for T
impl<T> MaybeResult<T> for T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
Source§impl<I, T> UpcastFrom<I, T> for T
impl<I, T> UpcastFrom<I, T> for T
fn upcast_from(from: T, _tcx: I) -> 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, cycle_error: &CycleError, _guar: ErrorGuaranteed, ) -> T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> MaybeSendSync for 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