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§

source

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

Oxford Join.

Join a slice of strings with Oxford Commas inserted as necessary.

Provided Methods§

source

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());
source

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());
source

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());
source

fn oxford_or(&self) -> Cow<'_, str>

Oxford Join (or).

This is equivalent to calling oxford_join(Conjunction::Or).

Examples
use oxford_join::{Conjunction, OxfordJoin};

let set = ["Apples", "Oranges"];
assert_eq!(set.oxford_join(Conjunction::Or), set.oxford_or());

Implementations on Foreign Types§

source§

impl<K, T> OxfordJoin for BTreeMap<K, T>
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 0]
where T: AsRef<str>,

source§

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]
where T: AsRef<str>,

source§

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]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

Oxford Join.

This is a special case; it will always read “first last”.

source§

impl<T> OxfordJoin for [T; 3]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 4]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 5]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 6]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 7]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 8]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 9]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 10]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 11]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 12]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 13]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 14]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 15]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 16]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 17]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 18]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 19]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 20]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 21]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 22]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 23]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 24]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 25]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 26]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 27]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 28]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 29]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 30]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 31]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T; 32]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for [T]
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

source§

impl<T> OxfordJoin for BTreeSet<T>
where T: AsRef<str>,

source§

fn oxford_join(&self, glue: Conjunction<'_>) -> Cow<'_, str>

Implementors§