Oxford Join
Join a slice of strings with Oxford Commas inserted as necessary, using the Conjunction of your choice.
(You know, as it should be. Haha.)
The return formatting depends on the size of the set:
0: ""
1: "first"
2: "first <CONJUNCTION> last"
n: "first, second, …, <CONJUNCTION> last"
This crate is #![no_std]-compatible.
Examples
The magic is accomplished with the OxfordJoin trait. Import that, and most
slice-y things holding AsRef<str> will inherit the OxfordJoin::oxford_join
method for joining.
use ;
let set = ;
assert_eq!;
let set = ;
assert_eq!;
// There are also shorthand methods for and, or, and_or, and nor, allowing you
// to skip the Conjunction enum entirely.
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
That's all, folks!
Installation
Add oxford_join to your dependencies in Cargo.toml, like:
[]
= "0.4.*"