pub struct HashMapper<T, const NBITS: usize>where
T: Hash,{ /* private fields */ }Expand description
Store hash-to-string association for a hash value
A hash mapping can be loaded from and written to files.
Such files store one line per hash, formatted as <hex-value> <string>.
Implementations§
Source§impl<T, const N: usize> HashMapper<T, N>
impl<T, const N: usize> HashMapper<T, N>
Sourcepub fn seek(&self, hash: T) -> HashOrStr<T, &str>
pub fn seek(&self, hash: T) -> HashOrStr<T, &str>
Return a matching string (if known) or the hash
Use this method to get a string representation with a fallback for unknown hashes.
let mut mapper = HashMapper::<u16>::new();
mapper.insert(42, "forty-two".to_string());
assert_eq!(format!("{}", mapper.seek(42)), "forty-two");
assert_eq!(format!("{}", mapper.seek(0x1234)), "{1234}");Source§impl<T, const N: usize> HashMapper<T, N>
impl<T, const N: usize> HashMapper<T, N>
Sourcepub fn from_reader<R: BufRead>(reader: R) -> Result<Self, HashError>
pub fn from_reader<R: BufRead>(reader: R) -> Result<Self, HashError>
Create a new mapping, loaded from a reader
Sourcepub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self, HashError>
pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self, HashError>
Create a new mapping, loaded from a file
Source§impl<T, const N: usize> HashMapper<T, N>
impl<T, const N: usize> HashMapper<T, N>
Trait Implementations§
Auto Trait Implementations§
impl<T, const NBITS: usize> Freeze for HashMapper<T, NBITS>
impl<T, const NBITS: usize> RefUnwindSafe for HashMapper<T, NBITS>where
T: RefUnwindSafe,
impl<T, const NBITS: usize> Send for HashMapper<T, NBITS>where
T: Send,
impl<T, const NBITS: usize> Sync for HashMapper<T, NBITS>where
T: Sync,
impl<T, const NBITS: usize> Unpin for HashMapper<T, NBITS>where
T: Unpin,
impl<T, const NBITS: usize> UnwindSafe for HashMapper<T, NBITS>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more