Skip to content

Commit

Permalink
feature: Add Position type alias to inc_search.
Browse files Browse the repository at this point in the history
  • Loading branch information
shanecelis committed Apr 22, 2024
1 parent defc56a commit 3c7247d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/inc_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,17 @@ pub struct IncSearch<'a, Label, Value> {
node: LoudsNodeNum,
}

/// Search position in the trie.
///
/// # Why do this?
///
/// "Position" is more descriptive for incremental search purposes, and without
/// it a user would have to explicitly depend on `louds-rs`.
pub type Position = LoudsNodeNum;

/// Retrieve the position the search is on. Useful for hanging on to a search
/// without having to fight the borrow checker.
impl<'a, L, V> From<IncSearch<'a, L, V>> for LoudsNodeNum {
/// without having to fight the borrow checker because its borrowing a trie.
impl<'a, L, V> From<IncSearch<'a, L, V>> for Position {
fn from(inc_search: IncSearch<'a, L, V>) -> Self {
inc_search.node
}
Expand Down Expand Up @@ -111,7 +119,7 @@ impl<'a, Label: Ord, Value> IncSearch<'a, Label, Value> {
/// assert_eq!(inc_search2.query_until("llo"), Ok(Answer::Match));
///
/// ```
pub fn resume(trie: &'a Trie<Label, Value>, position: LoudsNodeNum) -> Self {
pub fn resume(trie: &'a Trie<Label, Value>, position: Position) -> Self {
Self {
trie,
node: position
Expand Down

0 comments on commit 3c7247d

Please sign in to comment.