35 lines
823 B
Rust
35 lines
823 B
Rust
#[derive(Debug, Clone, PartialEq)]
|
|
pub struct Representation {
|
|
val: String,
|
|
}
|
|
|
|
impl Representation {
|
|
pub fn new(from: &str) -> Self {
|
|
Self {
|
|
val: from.to_string(),
|
|
}
|
|
}
|
|
|
|
pub fn from_choice(choice_parser_reps: &mut impl Iterator<Item = Representation>) -> Self {
|
|
let mut buf = String::new();
|
|
let mut iter = choice_parser_reps.peekable();
|
|
loop {
|
|
let rep = match iter.next() {
|
|
Some(r) => r,
|
|
None => break,
|
|
};
|
|
buf.push_str(&rep.val);
|
|
match iter.peek() {
|
|
Some(_) => {
|
|
buf.push_str(" | ");
|
|
}
|
|
None => {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
Representation::new(&buf)
|
|
}
|
|
}
|