Trait oxford_join::OxfordJoin
source · [−]pub trait OxfordJoin {
fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>;
fn oxford_and(&self) -> Cow<'_, str> { ... }
fn oxford_and_or(&self) -> Cow<'_, str> { ... }
fn oxford_nor(&self) -> Cow<'_, str> { ... }
fn oxford_or(&self) -> Cow<'_, str> { ... }
}
Expand description
Oxford Join.
Join a slice of strings with Oxford Commas inserted as necessary.
The return formatting depends on the size of the set:
ⓘ
"" // Zero.
"first" // One.
"first <CONJUNCTION> last" // Two.
"first, second, …, <CONJUNCTION> last" // Three+.
Examples
use oxford_join::{Conjunction, OxfordJoin};
let set = ["Apples"];
assert_eq!(set.oxford_join(Conjunction::And), "Apples");
let set = ["Apples", "Oranges"];
assert_eq!(set.oxford_join(Conjunction::And), "Apples and Oranges");
let set = ["Apples", "Oranges", "Bananas"];
assert_eq!(set.oxford_join(Conjunction::And), "Apples, Oranges, and Bananas");
Required Methods
fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>
fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>
Oxford Join.
Join a slice of strings with Oxford Commas inserted as necessary.
Provided Methods
fn oxford_and(&self) -> Cow<'_, str>
fn oxford_and(&self) -> Cow<'_, str>
Oxford Join (and).
This is equivalent to calling oxford_join(Conjunction::And)
.
Examples
use oxford_join::{Conjunction, OxfordJoin};
let set = ["Apples", "Oranges"];
assert_eq!(set.oxford_join(Conjunction::And), set.oxford_and());
fn oxford_and_or(&self) -> Cow<'_, str>
fn oxford_and_or(&self) -> Cow<'_, str>
Oxford Join (and/or).
This is equivalent to calling oxford_join(Conjunction::AndOr)
.
Examples
use oxford_join::{Conjunction, OxfordJoin};
let set = ["Apples", "Oranges"];
assert_eq!(set.oxford_join(Conjunction::AndOr), set.oxford_and_or());
fn oxford_nor(&self) -> Cow<'_, str>
fn oxford_nor(&self) -> Cow<'_, str>
Oxford Join (nor).
This is equivalent to calling oxford_join(Conjunction::Nor)
.
Examples
use oxford_join::{Conjunction, OxfordJoin};
let set = ["Apples", "Oranges"];
assert_eq!(set.oxford_join(Conjunction::Nor), set.oxford_nor());
Implementations on Foreign Types
sourceimpl<T> OxfordJoin for [T] where
T: AsRef<str>,
impl<T> OxfordJoin for [T] where
T: AsRef<str>,
sourcefn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>
fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>
sourceimpl<T> OxfordJoin for [T; 1] where
T: AsRef<str>,
impl<T> OxfordJoin for [T; 1] where
T: AsRef<str>,
sourcefn oxford_join(&self, _glue: Conjunction<'_>) -> Cow<'_, str>
fn oxford_join(&self, _glue: Conjunction<'_>) -> Cow<'_, str>
Oxford Join.
This is a special case; the only array entry will be returned as-is.
sourceimpl<T> OxfordJoin for [T; 2] where
T: AsRef<str>,
impl<T> OxfordJoin for [T; 2] where
T: AsRef<str>,
sourcefn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>
fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>
Oxford Join.
This is a special case; it will always read “first