Skip to main content

Delimit

Struct Delimit 

Source
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>

Source

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.

Source

pub fn with_last(self, last: &'a str) -> Self

Use last before the final item when formatting three or more items.

Source

pub fn with_pair(self, pair: &'a str) -> Self

Use pair when formatting exactly two items.

Trait Implementations§

Source§

impl<I> Display for Delimit<'_, I>
where I: Iterator<Item: Display>,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> DispatchRule<T> for T

Source§

type Error = Infallible

Errors that can occur during convert.
Source§

fn try_match(_from: &T) -> Result<MatchScore, FailureScore>

Attempt to match the value From to the type represented by Self. Read more
Source§

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>

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,

The equivalent of try_match but returns a reason for a failed score. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.