I got very confused and started mucking about with "spawn" when in fact all I needed was the "inline" extension type in orcx that allows the interpreter to expose custom constants.
27 lines
943 B
Rust
27 lines
943 B
Rust
use std::fmt;
|
|
|
|
use itertools::{Itertools, Position};
|
|
|
|
pub struct PrintList<'a, I: Iterator<Item = E> + Clone, E: fmt::Display>(pub I, pub &'a str);
|
|
impl<'a, I: Iterator<Item = E> + Clone, E: fmt::Display> fmt::Display for PrintList<'a, I, E> {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
for (pos, item) in self.0.clone().with_position() {
|
|
match pos {
|
|
Position::First | Position::Only => write!(f, "{item}")?,
|
|
Position::Middle => write!(f, ", {item}")?,
|
|
Position::Last => write!(f, ", {} {item}", self.1)?,
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
pub trait IteratorPrint: Iterator<Item: fmt::Display> + Clone {
|
|
/// Pretty-print a list with a comma-separated enumeration and an operator
|
|
/// word (such as "and" or "or") inserted before the last
|
|
fn display<'a>(self, operator: &'a str) -> PrintList<'a, Self, Self::Item> {
|
|
PrintList(self, operator)
|
|
}
|
|
}
|
|
impl<T: Iterator<Item: fmt::Display> + Clone> IteratorPrint for T {}
|