#[non_exhaustive]pub enum Signature<T> {
Sum {
count: u32,
},
Product,
Bool,
Int {
min: i128,
max: i128,
},
Char,
BigInt,
Opaque,
Array {
len: u32,
elem: T,
},
Slice {
elem: T,
},
}Expand description
The constructors that build the values of one type.
Each signature fixes which Pat constructors fit the type
and how they partition its values. Finite signatures can be covered
constructor by constructor; infinite ones need a wildcard (or, for
integers and characters, ranges that cover every value).
Types the signatures do not name directly map onto them:
(), tuples, structs, records,Box<T>and&T:Product.- enums and other tagged unions, including the never type
(
Sum { count: 0 }):Sum. - fixed-width integers:
Intwith the type’s bounds. Au128maps intoi128by flipping the top bit ((v ^ (1 << 127)) as i128), which preserves order. - floats:
Opaquewhen compared by equality, orIntover a total-order key of the bits when ranges are allowed. - strings and other interned values:
Opaque.
§Examples
use match_lang::Signature;
let u8_sig: Signature<()> = Signature::Int { min: 0, max: 255 };
let option_sig: Signature<()> = Signature::Sum { count: 2 };
assert_ne!(u8_sig, option_sig);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Sum
A tagged union with variants 0..count, matched by
Pat::variant. Each variant’s fields come from
Model::fields. count 0 is an empty type: no value, so a match
on it needs no arms.
Product
A type with exactly one constructor (a tuple, struct, record, box, or
reference), matched by Pat::product. Its
fields come from Model::fields with variant 0.
Bool
false and true, matched by Pat::bool.
Int
The integers min..=max, matched by Pat::int
and Pat::range. Covering every value from
min to max makes a match exhaustive.
Char
The Unicode scalar values ('\0'..='\u{10FFFF}' without the
surrogates), matched by Pat::char and
Pat::char_range.
BigInt
Integers without bounds (arbitrary precision). Patterns are i128
literals and ranges; values outside i128 can only be matched by a
wildcard, so a match is never exhaustive without one.
Opaque
Infinitely many values told apart only by equality: strings, floats
compared by value, symbols. Matched by Pat::lit;
a match always needs a wildcard.
Array
Arrays of exactly len elements of type elem, matched by
Pat::slice (with exactly len elements) and
Pat::slice_rest.
Slice
Sequences of any length of elements of type elem, matched by
Pat::slice and
Pat::slice_rest.
Fields
elem: TThe element type.