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

Oxford Join.

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

Provided Methods

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

Oxford Join.

This is a special case; the only array entry will be returned as-is.

Oxford Join.

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

Implementors