Function feruca::collate

source · []
pub fn collate(str_a: &str, str_b: &str, opt: &CollationOptions) -> Ordering
Expand description

This is, so far, the only public function in the library. It accepts as arguments two string references and a CollationOptions struct. It returns an Ordering value. This is designed to be used in conjunction with the sort_by function in the standard library. Simple usage might look like the following…

use feruca::{collate, CollationOptions};

let mut names = ["Peng", "Peña", "Ernie", "Émile"];
names.sort_by(|a, b| collate(a, b, &CollationOptions::default()));

let expected = ["Émile", "Ernie", "Peña", "Peng"];
assert_eq!(names, expected);

Significantly, in the event that two strings are ordered equally per the Unicode Collation Algorithm, this function will use byte-value comparison (i.e., the traditional, naïve way of sorting strings) as a tiebreaker. A collate_no_tiebreak function may be added in the future, if there is demand for it.