pub struct Adjustment {
    pub kind: Adjust,
    pub target: Ty,
}
Expand description

Represents coercing a value to a different type of value.

We transform values by following a number of Adjust steps in order. See the documentation on variants of Adjust for more details.

Here are some common scenarios:

  1. The simplest cases are where a pointer is not adjusted fat vs thin. Here the pointer will be dereferenced N times (where a dereference can happen to raw or borrowed pointers or any smart pointer which implements Deref, including Box<_>). The types of dereferences is given by autoderefs. It can then be auto-referenced zero or one times, indicated by autoref, to either a raw or borrowed pointer. In these cases unsize is false.

  2. A thin-to-fat coercion involves unsizing the underlying data. We start with a thin pointer, deref a number of times, unsize the underlying data, then autoref. The ‘unsize’ phase may change a fixed length array to a dynamically sized one, a concrete object to a trait object, or statically sized struct to a dynamically sized one. E.g., &[i32; 4] -> &i32 is represented by:

    Deref(None) -> [i32; 4],
    Borrow(AutoBorrow::Ref) -> &[i32; 4],
    Unsize -> &[i32],

    Note that for a struct, the ‘deep’ unsizing of the struct is not recorded. E.g., struct Foo<T> { x: T } we can coerce &Foo<[i32; 4]> to &Foo<i32> The autoderef and -ref are the same as in the above example, but the type stored in unsize is Foo<[i32]>, we don’t store any further detail about the underlying conversions from [i32; 4] to [i32].

  3. Coercing a Box<T> to Box<dyn Trait> is an interesting special case. In that case, we have the pointer we need coming in, so there are no autoderefs, and no autoref. Instead we just do the Unsize transformation. At some point, of course, Box should move out of the compiler, in which case this is analogous to transforming a struct. E.g., Box<[i32; 4]> -> Box<i32> is an Adjust::Unsize with the target Box<[i32]>.

Fields

kind: Adjusttarget: Ty

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

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

Cast a value to type U using CastTo.

Compare self to key and return true if they are equal.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. 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.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more