Struct Document

Source
pub struct Document<'a> { /* private fields */ }
Expand description

Allows you to do functions on the current line.

Implementations§

Source§

impl<'a> Document<'a>

Source

pub fn get_cursor_pos(&self) -> usize

Returns the current cursor position.

Source

pub fn get_whole_line(&self) -> &str

Returns the whole of the data stored in the document.

Source

pub fn get_char_relative_to_cursor(&self, offset: isize) -> Option<char>

Returns the char before the cursor. If the cursor is at zero or the doc is empty, will return None.

Source

pub fn text_before_cursor(&self) -> &str

Returns the text up until the cursor position. The cursor appears one ahead.

Source

pub fn text_after_cursor(&self) -> &str

Returns the text after the cursor.

Source

pub fn get_word_before_cursor(&self) -> &str

Returns a word before the cursor. A word is delimited by the start or end of the document, and space.

Source

pub fn get_word_after_cursor(&self) -> &str

Returns a word after the cursor. This includes the char on the cursor. A word is delimited by the start or end of the document, and space.

Source

pub fn get_word_before_cursor_with_space(&self) -> &str

Returns a word before the cursor including the spaces.

Source

pub fn get_word_after_cursor_with_space(&self) -> &str

Returns a word after the cursor including the spaces.

Source

pub fn get_word_before_cursor_until_sep(&self, sep: char) -> &str

Returns the word before the cursor until a separator is reached.

Examples found in repository?
examples/basic.rs (line 15)
7    fn get_suggestions(&self, doc: Document) -> Vec<Suggestion> {
8        let mut suggestions = vec![
9            Suggestion::new("find", "Find something"),
10            Suggestion::new("go", "Go somewhere"),
11            Suggestion::new("die", "kills something"),
12            Suggestion::new("flame", "flames something"),
13            Suggestion::new("Blank_Desc", ""),
14        ];
15        let filter = doc.get_word_before_cursor_until_sep(' ');
16        if filter == "" {
17            suggestions
18        } else {
19            suggestions.retain(|v| v.get_name().contains(filter));
20            suggestions
21        }
22    }
Source

pub fn get_word_after_cursor_until_sep(&self, sep: char) -> &str

Returns the word after the cursor until a separator is reached.

Source

pub fn get_word_before_cursor_until_sep_ignore_next_to_cursor( &self, sep: char, ) -> &str

Returns a word before the cursor until a separator is reached. Ignores the char next to the cursor.

Source

pub fn get_word_after_cursor_until_sep_ignore_next_to_cursor( &self, sep: char, ) -> &str

Returns a word after the cursor until a separator is reached. Ignores the char next to the cursor.

Auto Trait Implementations§

§

impl<'a> Freeze for Document<'a>

§

impl<'a> RefUnwindSafe for Document<'a>

§

impl<'a> Send for Document<'a>

§

impl<'a> Sync for Document<'a>

§

impl<'a> Unpin for Document<'a>

§

impl<'a> UnwindSafe for Document<'a>

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> 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, 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.