pub struct Delimit<'a, I> { /* private fields */ }Expand description
Formats an iterator with a delimiter between items and optional overrides for the final delimiter and pair formatting.
This is a single-use wrapper: the iterator is consumed on the first call to Display::fmt.
Subsequent calls will print <missing>.
Use Delimit::with_last to change the delimiter before the final item
(e.g., ", and "), which is useful for natural-language lists like
"a, b, and c".
Use Delimit::with_pair to change formatting when there are only two items.
§Examples
use diskann_benchmark_runner::utils::fmt::Delimit;
let d = Delimit::new(["a", "b", "c"], ", ").with_last(", and ");
assert_eq!(d.to_string(), "a, b, and c");
let d = Delimit::new(["a", "b"], ", ").with_last(", and ");
assert_eq!(d.to_string(), "a, and b");
let d = Delimit::new(["a", "b"], ", ")
.with_last(", and ")
.with_pair(" and ");
assert_eq!(d.to_string(), "a and b");Implementations§
Source§impl<'a, I> Delimit<'a, I>
impl<'a, I> Delimit<'a, I>
Sourcepub fn new(itr: impl IntoIterator<IntoIter = I>, delimiter: &'a str) -> Self
pub fn new(itr: impl IntoIterator<IntoIter = I>, delimiter: &'a str) -> Self
Create a new Delimit from an iterable and a delimiter.
By default, the same delimiter is used between every item. Use
Self::with_last and Self::with_pair to opt into special handling
before the final item or for pairs.
Trait Implementations§
Auto Trait Implementations§
impl<'a, I> !Freeze for Delimit<'a, I>
impl<'a, I> !RefUnwindSafe for Delimit<'a, I>
impl<'a, I> Send for Delimit<'a, I>where
I: Send,
impl<'a, I> !Sync for Delimit<'a, I>
impl<'a, I> Unpin for Delimit<'a, I>where
I: Unpin,
impl<'a, I> UnsafeUnpin for Delimit<'a, I>where
I: UnsafeUnpin,
impl<'a, I> UnwindSafe for Delimit<'a, I>where
I: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> DispatchRule<T> for T
impl<T> DispatchRule<T> for T
Source§type Error = Infallible
type Error = Infallible
Errors that can occur during
convert.Source§fn try_match(_from: &T) -> Result<MatchScore, FailureScore>
fn try_match(_from: &T) -> Result<MatchScore, FailureScore>
Source§fn convert(from: T) -> Result<T, <T as DispatchRule<T>>::Error>
fn convert(from: T) -> Result<T, <T as DispatchRule<T>>::Error>
Perform the actual conversion. Read more
Source§fn description(f: &mut Formatter<'_>, from: Option<&T>) -> Result<(), Error>
fn description(f: &mut Formatter<'_>, from: Option<&T>) -> Result<(), Error>
Write a description of the dispatch rule and outcome to the formatter. Read more
Source§fn try_match_verbose<'a>(
from: &'a From,
) -> Result<MatchScore, TaggedFailureScore<'a>>where
Self: 'a,
fn try_match_verbose<'a>(
from: &'a From,
) -> Result<MatchScore, TaggedFailureScore<'a>>where
Self: 'a,
The equivalent of
try_match but returns a reason for a failed score. Read more