Skip to main content

Signature

Enum Signature 

Source
#[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: Int with the type’s bounds. A u128 maps into i128 by flipping the top bit ((v ^ (1 << 127)) as i128), which preserves order.
  • floats: Opaque when compared by equality, or Int over 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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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.

Fields

§count: u32

The number of variants.

§

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.

Fields

§min: i128

The smallest value of the type.

§max: i128

The largest value of the type.

§

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.

Fields

§len: u32

The array length.

§elem: T

The element type.

§

Slice

Sequences of any length of elements of type elem, matched by Pat::slice and Pat::slice_rest.

Fields

§elem: T

The element type.

Trait Implementations§

Source§

impl<T: Clone> Clone for Signature<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Signature<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Eq> Eq for Signature<T>

Source§

impl<T: Hash> Hash for Signature<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl<T: PartialEq> PartialEq for Signature<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for Signature<T>

Auto Trait Implementations§

§

impl<T> Freeze for Signature<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Signature<T>
where T: RefUnwindSafe,

§

impl<T> Send for Signature<T>
where T: Send,

§

impl<T> Sync for Signature<T>
where T: Sync,

§

impl<T> Unpin for Signature<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Signature<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Signature<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.