pub enum Scalar<Prov = AllocId> {
    Int(ScalarInt),
    Ptr(Pointer<Prov>, u8),
}
Expand description

A Scalar represents an immediate, primitive value existing outside of a memory::Allocation. It is in many ways like a small chunk of an Allocation, up to 16 bytes in size. Like a range of bytes in an Allocation, a Scalar can either represent the raw bytes of a simple value or a pointer into another Allocation

These variants would be private if there was a convenient way to achieve that in Rust. Do not match on a Scalar! Use the various to_* methods instead.

Variants

Int(ScalarInt)

The raw bytes of a simple value.

Ptr(Pointer<Prov>, u8)

A pointer.

We also store the size of the pointer, such that a Scalar always knows how big it is. The size is always the pointer size of the current target, but this is not information that we always have readily available.

Implementations

Create a Scalar from a pointer with an Option<_> provenance (where None represents a plain integer / “invalid” pointer).

This is almost certainly not the method you want! You should dispatch on the type and use to_{u8,u16,...}/scalar_to_ptr to perform ptr-to-int / int-to-ptr casts as needed.

This method only exists for the benefit of low-level operations that truly need to treat the scalar in whatever form it is.

This throws UB (instead of ICEing) on a size mismatch since size mismatches can arise in Miri when someone declares a function that we shim (such as malloc) with a wrong type.

Fundamental scalar-to-int (cast) operation. Many convenience wrappers exist below, that you likely want to use instead.

Will perform ptr-to-int casts if needed and possible. If that fails, we know the offset is relative, so we return an “erased” Scalar (which is useful for error messages but not much else).

This throws UB (instead of ICEing) on a size mismatch since size mismatches can arise in Miri when someone declares a function that we shim (such as malloc) with a wrong type.

Converts the scalar to produce an unsigned integer of the given size. Fails if the scalar is a pointer.

Converts the scalar to produce a u8. Fails if the scalar is a pointer.

Converts the scalar to produce a u16. Fails if the scalar is a pointer.

Converts the scalar to produce a u32. Fails if the scalar is a pointer.

Converts the scalar to produce a u64. Fails if the scalar is a pointer.

Converts the scalar to produce a u128. Fails if the scalar is a pointer.

Converts the scalar to produce a machine-pointer-sized unsigned integer. Fails if the scalar is a pointer.

Converts the scalar to produce a signed integer of the given size. Fails if the scalar is a pointer.

Converts the scalar to produce an i8. Fails if the scalar is a pointer.

Converts the scalar to produce an i16. Fails if the scalar is a pointer.

Converts the scalar to produce an i32. Fails if the scalar is a pointer.

Converts the scalar to produce an i64. Fails if the scalar is a pointer.

Converts the scalar to produce an i128. Fails if the scalar is a pointer.

Converts the scalar to produce a machine-pointer-sized signed integer. Fails if the scalar is a pointer.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
Formats the value using the given formatter.
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
The entry point for folding. To fold a value t with a folder f call: t.try_fold_with(f). Read more
A convenient alternative to try_fold_with for use with infallible folders. Do not override this method, to ensure coherence with try_fold_with. Read more
The entry point for visiting. To visit a value t with a visitor v call: t.visit_with(v). Read more
Returns true if self has any late-bound regions that are either bound by binder or bound by some binder outside of binder. If binder is ty::INNERMOST, this indicates whether there are any late-bound regions that appear free. Read more
Returns true if this self has any regions that escape binder (and hence are not bound by it). Read more
“Free” regions in this context means that it has any region that is not (a) erased or (b) late-bound. Read more
True if there are any un-erased free regions.
Indicates whether this value references only ‘global’ generic parameters that are the same regardless of what fn we are in. This is used for caching. Read more
True if there are any late-bound regions
Indicates whether this value still has parameters/placeholders/inference variables which could be replaced later, in a way that would change the results of impl specialization. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
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
This method tries to recover the query key from the given DepNode, something which is needed when forcing DepNodes 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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.

Layout

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.