pub(super) struct Fields<'p, 'tcx> {
    fields: &'p [DeconstructedPat<'p, 'tcx>],
}
Expand description

A value can be decomposed into a constructor applied to some fields. This struct represents those fields, generalized to allow patterns in each field. See also Constructor.

This is constructed for a constructor using Fields::wildcards(). The idea is that Fields::wildcards() constructs a list of fields where all entries are wildcards, and then given a pattern we fill some of the fields with its subpatterns. In the following example Fields::wildcards returns [_, _, _, _]. Then in extract_pattern_arguments we fill some of the entries, and the result is [Some(0), _, _, _].

let x: [Option<u8>; 4] = foo();
match x {
    [Some(0), ..] => {}
}

Note that the number of fields of a constructor may not match the fields declared in the original struct/variant. This happens if a private or non_exhaustive field is uninhabited, because the code mustn’t observe that it is uninhabited. In that case that field is not included in fields. For that reason, when you have a mir::Field you must use index_with_declared_idx.

Fields§

§fields: &'p [DeconstructedPat<'p, 'tcx>]

Implementations§

Creates a new list of wildcard fields for a given constructor. The result must have a length of constructor.arity().

Returns the list of patterns.

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

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

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
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: 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: 16 bytes