Add an arm that reads fields to the Match statement.
(&mut self, name: T, fields: Vec<S>, body: T)
| 346 | |
| 347 | /// Add an arm that reads fields to the Match statement. |
| 348 | pub fn arm<T: Into<String>, S: Into<String>>(&mut self, name: T, fields: Vec<S>, body: T) { |
| 349 | let name = name.into(); |
| 350 | assert!( |
| 351 | name != "_", |
| 352 | "catch all clause can't extract fields, use arm_no_fields instead." |
| 353 | ); |
| 354 | |
| 355 | let body = body.into(); |
| 356 | let fields = fields.into_iter().map(|x| x.into()).collect(); |
| 357 | let match_arm = self |
| 358 | .arms |
| 359 | .entry((fields, body)) |
| 360 | .or_insert_with(BTreeSet::new); |
| 361 | match_arm.insert(name); |
| 362 | } |
| 363 | |
| 364 | /// Adds an arm that doesn't read anythings from the fields to the Match statement. |
| 365 | pub fn arm_no_fields(&mut self, name: impl Into<String>, body: impl Into<String>) { |