Skip to main content

canonical

Function canonical 

Source
pub fn canonical<'a>(candidate: &str, declared: &[&'a str]) -> Option<&'a str>
Expand description

Which of declared the user meant by candidate, if exactly one.

An exact match wins outright, so the common case costs one comparison and cannot regress. Otherwise a candidate matches a declaration when the two normalize alike, and only an unambiguous match counts.

None means the caller should pass candidate through untouched rather than guess. That is what keeps a plugin’s own #[serde(alias)] spellings working, since serde does not report aliases alongside the names it declares, and what leaves an unknown identifier to be reported by whoever owns the vocabulary.