cranelift_codegen_meta::srcgen

Struct Match

Source
pub(crate) struct Match {
    expr: String,
    arms: BTreeMap<(Vec<String>, String), BTreeSet<String>>,
    catch_all: Option<String>,
}
Expand description

Match formatting class.

Match objects collect all the information needed to emit a Rust match expression, automatically deduplicating overlapping identical arms.

Note that this class is ignorant of Rust types, and considers two fields with the same name to be equivalent. BTreeMap/BTreeSet are used to represent the arms in order to make the order deterministic.

Fields§

§expr: String§arms: BTreeMap<(Vec<String>, String), BTreeSet<String>>§catch_all: Option<String>

The clause for the placeholder pattern _.

Implementations§

Source§

impl Match

Source

pub fn new(expr: impl Into<String>) -> Self

Create a new match statement on expr.

Source

fn set_catch_all(&mut self, clause: String)

Source

pub fn arm<T: Into<String>, S: Into<String>>( &mut self, name: T, fields: Vec<S>, body: T, )

Add an arm that reads fields to the Match statement.

Source

pub fn arm_no_fields( &mut self, name: impl Into<String>, body: impl Into<String>, )

Adds an arm that doesn’t read anythings from the fields to the Match statement.

Auto Trait Implementations§

§

impl Freeze for Match

§

impl RefUnwindSafe for Match

§

impl Send for Match

§

impl Sync for Match

§

impl Unpin for Match

§

impl UnwindSafe for Match

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.