CompletionTree

Struct CompletionTree 

Source
pub struct CompletionTree { /* private fields */ }
Expand description

A completion tree that holds and handles completions

Implementations§

Source§

impl CompletionTree

Source

pub fn with_inclusions(incl: &[char]) -> Self

Create a new CompletionTree with provided non alphabet characters whitelisted. The default CompletionTree will only parse alphabet characters (a-z, A-Z). Use this to introduce additional accepted special characters.

§Arguments
  • incl An array slice with allowed characters
§Example
extern crate rs_complete;
use rs_complete::CompletionTree;

let mut completions = CompletionTree::default();
completions.insert("test-hyphen test_underscore");
assert_eq!(
    completions.complete("te"),
    Some(vec!["test".to_string()]));

let mut completions = CompletionTree::with_inclusions(&['-', '_']);
completions.insert("test-hyphen test_underscore");
assert_eq!(
    completions.complete("te"),
    Some(vec!["test-hyphen".to_string(), "test_underscore".to_string()]));
Source

pub fn insert(&mut self, line: &str)

Inserts one or more words into the completion tree for later use. Input is automatically split using the defined WordSeparator (see CompletionTree::separator).

§Arguments
  • line A str slice containing one or more words
§Example
extern crate rs_complete;
use rs_complete::CompletionTree;

let mut completions = CompletionTree::default();
completions.set_min_word_len(1);

// Insert multiple words
completions.insert("a line with many words");
assert_eq!(completions.word_count(), 5);
completions.clear();
assert_eq!(completions.word_count(), 0);

// The above line is equal to the following:
completions.insert("a");
completions.insert("line");
completions.insert("with");
completions.insert("many");
completions.insert("words");
assert_eq!(completions.word_count(), 5);
Source

pub fn separator(&mut self, separator: WordSeparator)

Changes the word separator used by CompletionTree::insert() If left unchanged the default is WordSeparator::Whitespace

§Arguments
  • separator A WordSeparator
§Example
extern crate rs_complete;
use rs_complete::{CompletionTree, WordSeparator};

let mut completions = CompletionTree::default();
completions.separator(WordSeparator::Separator("|"));
completions.set_min_word_len(1);

// Insert multiple words
completions.insert("a|line|with|many|words");
assert_eq!(completions.word_count(), 5);
completions.clear();
assert_eq!(completions.word_count(), 0);

// The above line is equal to the following:
completions.insert("a");
completions.insert("line");
completions.insert("with");
completions.insert("many");
completions.insert("words");
assert_eq!(completions.word_count(), 5);
Source

pub fn complete(&self, line: &str) -> Option<Vec<String>>

Returns an optional vector of completions based on the provided input

§Arguments
  • line The line to complete In case of multiple words, only the last will be completed
§Example
extern crate rs_complete;
use rs_complete::CompletionTree;

let mut completions = CompletionTree::default();
completions.insert("batman robin batmobile batcave robber");
assert_eq!(
    completions.complete("bat"),
    Some(vec!["batcave", "batman", "batmobile"].iter().map(|s| s.to_string()).collect()));

assert_eq!(
    completions.complete("to the bat"),
    Some(vec!["to the batcave", "to the batman", "to the batmobile"].iter().map(|s| s.to_string()).collect()));
Source

pub fn clear(&mut self)

Clears all the data from the tree

§Example
extern crate rs_complete;
use rs_complete::CompletionTree;

let mut completions = CompletionTree::default();
completions.insert("batman robin batmobile batcave robber");
assert_eq!(completions.word_count(), 5);
assert_eq!(completions.size(), 24);
completions.clear();
assert_eq!(completions.size(), 1);
assert_eq!(completions.word_count(), 0);
Source

pub fn word_count(&self) -> u32

Returns a count of how many words that exist in the tree

§Example
extern crate rs_complete;
use rs_complete::CompletionTree;

let mut completions = CompletionTree::default();
completions.insert("batman robin batmobile batcave robber");
assert_eq!(completions.word_count(), 5);
Source

pub fn size(&self) -> u32

Returns the size of the tree, the amount of nodes, not words

§Example
extern crate rs_complete;
use rs_complete::CompletionTree;

let mut completions = CompletionTree::default();
completions.insert("batman robin batmobile batcave robber");
assert_eq!(completions.size(), 24);
Source

pub fn min_word_len(&self) -> usize

Returns the minimum word length to complete. This allows you to pass full sentences to insert() and not worry about pruning out small words like “a” or “to”, because they will be ignored.

§Example
extern crate rs_complete;
use rs_complete::CompletionTree;

let mut completions = CompletionTree::default();
completions.set_min_word_len(4);
completions.insert("one two three four five");
assert_eq!(completions.word_count(), 3);

let mut completions = CompletionTree::default();
completions.set_min_word_len(1);
completions.insert("one two three four five");
assert_eq!(completions.word_count(), 5);
Source

pub fn set_min_word_len(&mut self, len: usize)

Sets the minimum word length to complete on. Smaller words are ignored. This only affects future calls to insert() - changing this won’t start completing on smaller words that were added in the past, nor will it exclude larger words already inserted into the completion tree.

Trait Implementations§

Source§

impl Clone for CompletionTree

Source§

fn clone(&self) -> CompletionTree

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CompletionTree

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CompletionTree

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.