pub struct NicknameTable { /* private fields */ }Expand description
Equivalence-class lookup table for given-name nicknames.
Each class is a Vec<String> of normalised forms that the table
considers interchangeable. Two inputs are equivalent under the table
iff their normalised forms appear in the same class — or are
byte-identical after normalisation.
The type is Clone + Debug + PartialEq + Eq so it composes into
crate::MatchConfig without surprises. Construction is cheap and
allocates once per class; lookup is O(classes × entries) and is
dominated by the table’s size, not the input string length.
§Example
use worker_matcher::NicknameTable;
let t = NicknameTable::empty()
.with_class(["Michael", "Mike", "Mickey"])
.with_class(["Elizabeth", "Liz", "Beth"]);
assert!(t.are_equivalent("Mike", "Michael"));
assert!(t.are_equivalent("liz", "BETH"));
assert!(!t.are_equivalent("Michael", "Liz"));Implementations§
Source§impl NicknameTable
impl NicknameTable
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Construct an empty table that considers every pair of distinct strings non-equivalent (identical strings remain trivially equal).
use worker_matcher::NicknameTable;
let t = NicknameTable::empty();
assert!(!t.are_equivalent("Mike", "Michael"));
assert!(t.are_equivalent("Mike", "Mike"));Sourcepub fn with_class<I, S>(self, names: I) -> Self
pub fn with_class<I, S>(self, names: I) -> Self
Append an equivalence class to the table.
Each input string is normalised via
crate::Normalizer::normalize_name before insertion so the
table is closed under the same normalisation pipeline the matcher
uses at lookup time. Duplicate or empty entries are silently
dropped, and a class with fewer than two distinct normalised
entries is dropped entirely (it would never make a pair
equivalent).
use worker_matcher::NicknameTable;
let t = NicknameTable::empty().with_class(["Robert", "Bob", "Rob"]);
assert!(t.are_equivalent("BOB", "robert"));Sourcepub fn are_equivalent(&self, a: &str, b: &str) -> bool
pub fn are_equivalent(&self, a: &str, b: &str) -> bool
Return true iff a and b, after name normalisation, are
considered the same worker by this table.
Identical normalised strings are trivially equivalent. Otherwise both inputs must appear in the same equivalence class.
use worker_matcher::NicknameTable;
let t = NicknameTable::english();
assert!(t.are_equivalent("Mike", "Michael"));
assert!(t.are_equivalent("mike", "MICHAEL")); // case-insensitive
assert!(!t.are_equivalent("Mike", "Robert"));
assert!(t.are_equivalent("", "")); // trivially equalSourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
true iff the table contains no equivalence classes — equivalent
to comparing with NicknameTable::empty but cheaper to test.
use worker_matcher::NicknameTable;
assert!(NicknameTable::empty().is_empty());
assert!(!NicknameTable::english().is_empty());Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of equivalence classes registered with this table.
use worker_matcher::NicknameTable;
assert_eq!(NicknameTable::empty().len(), 0);
let t = NicknameTable::empty().with_class(["A", "B"]);
assert_eq!(t.len(), 1);Sourcepub fn english() -> Self
pub fn english() -> Self
A built-in table covering the most common English-language
nicknames encountered in healthcare data: Michael/Mike,
Robert/Bob, Elizabeth/Liz, and similar.
The exact contents are not part of the public contract — entries
may be added in minor releases. Callers that need a stable
dictionary SHOULD construct their own via
NicknameTable::with_class.
use worker_matcher::NicknameTable;
let t = NicknameTable::english();
assert!(t.are_equivalent("Bill", "William"));
assert!(t.are_equivalent("Liz", "Elizabeth"));
assert!(t.are_equivalent("Steve", "Steven"));
assert!(t.are_equivalent("Steve", "Stephen"));Trait Implementations§
Source§impl Clone for NicknameTable
impl Clone for NicknameTable
Source§fn clone(&self) -> NicknameTable
fn clone(&self) -> NicknameTable
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NicknameTable
impl Debug for NicknameTable
Source§impl Default for NicknameTable
impl Default for NicknameTable
Source§fn default() -> NicknameTable
fn default() -> NicknameTable
Source§impl<'de> Deserialize<'de> for NicknameTable
impl<'de> Deserialize<'de> for NicknameTable
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for NicknameTable
impl PartialEq for NicknameTable
Source§fn eq(&self, other: &NicknameTable) -> bool
fn eq(&self, other: &NicknameTable) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for NicknameTable
impl Serialize for NicknameTable
impl Eq for NicknameTable
impl StructuralPartialEq for NicknameTable
Auto Trait Implementations§
impl Freeze for NicknameTable
impl RefUnwindSafe for NicknameTable
impl Send for NicknameTable
impl Sync for NicknameTable
impl Unpin for NicknameTable
impl UnsafeUnpin for NicknameTable
impl UnwindSafe for NicknameTable
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more