[][src]Struct rs_complete::CompletionTree

pub struct CompletionTree { /* fields omitted */ }

A completion tree that holds and handles completions

Implementations

impl CompletionTree[src]

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

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()]));

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

Inserts one or more words into the completion tree for later use. Input is automatically split on 'whitespace' using String::split_whitespace().

Arguments

  • line A str slice containing one or more words

Example

extern crate rs_complete;
use rs_complete::CompletionTree;

let mut completions = CompletionTree::default();

// Insert multiple words
completions.insert("a line with many words");

// The above line is equal to the following:
completions.insert("a");
completions.insert("line");
completions.insert("with");
completions.insert("many");
completions.insert("words");

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

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()));

pub fn clear(&mut self)[src]

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);

pub fn word_count(&self) -> u32[src]

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);

pub fn size(&self) -> u32[src]

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);

Trait Implementations

impl Clone for CompletionTree[src]

impl Debug for CompletionTree[src]

impl Default for CompletionTree[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.