MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / add_match

Method add_match

cranelift/srcgen/src/lib.rs:196–232  ·  view source on GitHub ↗

Add a match expression.

(&mut self, m: Match)

Source from the content-addressed store, hash-verified

194
195 /// Add a match expression.
196 pub fn add_match(&mut self, m: Match) {
197 assert!(matches!(self.lang, Language::Rust));
198 fmtln!(self, "match {} {{", m.expr);
199 self.indent(|fmt| {
200 for (&(ref fields, ref body), ref names) in m.arms.iter() {
201 // name { fields } | name { fields } => { body }
202 let conditions = names
203 .iter()
204 .map(|name| {
205 if !fields.is_empty() {
206 format!("{} {{ {} }}", name, fields.join(", "))
207 } else {
208 name.clone()
209 }
210 })
211 .collect::<Vec<_>>()
212 .join(" |\n")
213 + " => {";
214
215 fmt.multi_line(&conditions);
216 fmt.indent(|fmt| {
217 fmt.line(body);
218 });
219 fmt.line("}");
220 }
221
222 // Make sure to include the catch all clause last.
223 if let Some(body) = m.catch_all {
224 fmt.line("_ => {");
225 fmt.indent(|fmt| {
226 fmt.line(body);
227 });
228 fmt.line("}");
229 }
230 });
231 self.line("}");
232 }
233
234 /// Write `self.lines` to a file.
235 pub fn write(

Callers 8

adding_arms_worksFunction · 0.80
gen_getterFunction · 0.80
gen_formatsFunction · 0.80
gen_arguments_methodFunction · 0.80
gen_bool_accessorFunction · 0.80
gen_opcodesFunction · 0.80

Calls 8

multi_lineMethod · 0.80
indentMethod · 0.45
iterMethod · 0.45
joinMethod · 0.45
mapMethod · 0.45
is_emptyMethod · 0.45
cloneMethod · 0.45
lineMethod · 0.45

Tested by 2

adding_arms_worksFunction · 0.64