Trait oxford_join::OxfordJoin
source · 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>
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());
sourcefn 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());
sourcefn 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§
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>
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