Skip to content

Commit

Permalink
Add plural versions for ChoiceOption::{option,export}
Browse files Browse the repository at this point in the history
  • Loading branch information
tingerrr committed Nov 13, 2023
1 parent 387602e commit c1bbb57
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/forms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,31 @@ impl<'a> ChoiceOptions<'a> {
self
}

/// Add options with the given values.
pub fn options<'b>(
&mut self,
values: impl IntoIterator<Item = TextStr<'b>>,
) -> &mut Self {
self.array.items(values);
self
}

/// Add an option with the given value and export value.
pub fn export(&mut self, value: TextStr, export_value: TextStr) -> &mut Self {
self.array.push().array().items([export_value, value]);
self
}

/// Add options with the given pairs of value and export value.
pub fn exports<'b>(
&mut self,
values: impl IntoIterator<Item = (TextStr<'b>, TextStr<'b>)>,
) -> &mut Self {
for (value, export) in values {
self.export(value, export);
}
self
}
}

deref!('a, ChoiceOptions<'a> => Array<'a>, array);
Expand Down

0 comments on commit c1bbb57

Please sign in to comment.