#[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 = _
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 try_from_target_usize( i: impl Into<u128>, tcx: TyCtxt<'_> ) -> Option<Self>
pub fn assert_bits(self, target_size: Size) -> u128
pub fn to_bits(self, target_size: Size) -> Result<u128, 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 not equal 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.
pub fn try_to_target_usize(&self, tcx: TyCtxt<'_>) -> Result<u64, Size>
pub fn try_to_bool(self) -> Result<bool, Size>
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 not equal 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 not equal 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 not equal 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 not equal 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 not equal 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 not equal to Size { raw: 16 }
and returns the ScalarInt
s size in that case.
pub fn try_to_target_isize(&self, tcx: TyCtxt<'_>) -> Result<i64, Size>
pub fn try_to_float<F: Float>(self) -> Result<F, Size>
pub fn try_to_f16(self) -> Result<Half, Size>
pub fn try_to_f32(self) -> Result<Single, Size>
pub fn try_to_f64(self) -> Result<Double, Size>
pub fn try_to_f128(self) -> Result<Quad, Size>
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 PartialEq for ScalarInt
impl PartialEq for ScalarInt
source§impl PartialOrd for ScalarInt
impl PartialOrd 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 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§
§impl<T> AnyEq for T
impl<T> AnyEq for 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<'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> 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<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, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
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
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Filterable for T
impl<T> Filterable for T
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<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
§impl<T> Pointable for T
impl<T> Pointable 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, 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