mod prefix;
use std::{cmp::Ordering, fmt::Display};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[cfg(feature = "wasm")]
use wasm_bindgen::prelude::*;
#[derive(PartialEq, Eq, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "wasm", wasm_bindgen(getter_with_clone))]
pub struct MeasuredString {
pub string: String,
pub distance: usize,
}
impl Ord for MeasuredString {
fn cmp(&self, other: &Self) -> Ordering {
self.distance
.cmp(&other.distance)
.then_with(|| self.string.cmp(&other.string))
}
}
#[derive(PartialEq, Eq, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "wasm", wasm_bindgen(getter_with_clone))]
pub struct MeasuredPrefix {
pub string: String,
pub prefix_distance: usize,
}
impl Ord for MeasuredPrefix {
fn cmp(&self, other: &Self) -> Ordering {
self.prefix_distance
.cmp(&other.prefix_distance)
.then_with(|| self.string.cmp(&other.string))
}
}
impl PartialOrd for MeasuredString {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl PartialOrd for MeasuredPrefix {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Display for MeasuredPrefix {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"(string: {}, PED: {})",
self.string, self.prefix_distance
)
}
}
#[doc(inline)]
pub type Autocompleter<'stored, U = u8, S = u32> = prefix::Autocompleter<'stored, U, S>;