harper_core/spell/
word_id.rs1use std::hash::BuildHasher;
2
3use foldhash::fast::FixedState;
4use serde::{Deserialize, Serialize};
5
6use crate::{CharString, CharStringExt};
7
8#[derive(Hash, Copy, Clone, PartialEq, Eq, PartialOrd, Debug, Serialize, Deserialize)]
14pub struct WordId {
15 hash: u64,
16}
17
18impl WordId {
19 pub fn from_word_chars(chars: impl AsRef<[char]>) -> Self {
21 let normalized = chars.as_ref().normalized();
22 let lower = normalized.to_lower();
23 let hash = FixedState::default().hash_one(lower);
24
25 Self { hash }
26 }
27
28 pub fn from_word_str(text: impl AsRef<str>) -> Self {
31 let chars: CharString = text.as_ref().chars().collect();
32 Self::from_word_chars(chars)
33 }
34}