pub trait OxfordJoin {
// Required method
fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>;
// Provided methods
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::Or), "Apples or Oranges");
let set = ["Apples", "Oranges", "Bananas"];
assert_eq!(set.oxford_join(Conjunction::AndOr), "Apples, Oranges, and/or Bananas");
Required Methods§
Sourcefn 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§
Sourcefn oxford_and(&self) -> Cow<'_, str>
fn oxford_and(&self) -> Cow<'_, str>
Sourcefn oxford_and_or(&self) -> Cow<'_, str>
fn oxford_and_or(&self) -> Cow<'_, str>
Sourcefn oxford_nor(&self) -> Cow<'_, str>
fn oxford_nor(&self) -> Cow<'_, str>
Implementations on Foreign Types§
Source§impl<K, T> OxfordJoin for BTreeMap<K, T>
impl<K, T> OxfordJoin for BTreeMap<K, T>
Source§fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>
fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>
§Oxford Join.
Source§impl<T> OxfordJoin for [T; 0]
impl<T> OxfordJoin for [T; 0]
Source§fn oxford_join(&self, _glue: Conjunction<'_>) -> Cow<'_, str>
fn oxford_join(&self, _glue: Conjunction<'_>) -> Cow<'_, str>
§Oxford Join.
This is a special case; the result is always empty.
Source§impl<T> OxfordJoin for [T; 1]
impl<T> OxfordJoin for [T; 1]
Source§fn oxford_join(&self, _glue: Conjunction<'_>) -> Cow<'_, str>
fn oxford_join(&self, _glue: Conjunction<'_>) -> Cow<'_, str>
§Oxford Join.
This is a special case; the sole entry will be returned as-is.
Source§impl<T> OxfordJoin for [T; 2]
impl<T> OxfordJoin for [T; 2]
Source§fn 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 CONJUNCTION last”.