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.