Skip to main content

HookBuilder

Struct HookBuilder 

Source
pub struct HookBuilder<H: Hookable> { /* private fields */ }
Expand description

A struct used in order to specify more options for hooks.

You can set three options currently:

Implementations§

Source§

impl<H: Hookable> HookBuilder<H>

Source

pub fn grouped(self, ns: Ns) -> Self

Groups this hook with a namespace.

By adding a namespace to this group, you are then able to remove a group of hooks by calling hook::remove.

Source

pub fn filter<T: Send + 'static>(self, filter: T) -> Self
where H: PartialEq<T>,

Filter when this hook will be called.

This is mostly for convenience’s sake, since you could just add a check inside of the callback itself.

This is useful if for example, you want to trigger a hook on only some specific Handle, or some Buffer, things of the sort.

Source

pub fn lateness(self, lateness: usize) -> Self

Set the “lateness” of this hook.

The lateness determines how “late” a hook should be applied. For example, if a hook has a lateness of 0 and another has a lateness of usize::MAX, the latter one will be triggered after the first one.

An example of where this is useful is with hooks that need to know which lines were printed. For example, if I print the line numbers, and then in a later hook in the same BufferUpdated trigger, an edit is made, the printed line numbers may now be wrong.

The general wisdom is that, in order to not break things, if your hook relies on meta Tags (Inlay, Conceal or Spacer) or edits the Text of the Buffer, you should make use of a lower lateness.

If it only makes use of “light” Tags (like FormTag) or relies on no future changes on the same BufferUpdated trigger (by e.g. getting the printed lines), then it should have a higher lateness.

By default, every hook has a lateness of 100.

Trait Implementations§

Source§

impl<H: Hookable> Drop for HookBuilder<H>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<H> Freeze for HookBuilder<H>

§

impl<H> !RefUnwindSafe for HookBuilder<H>

§

impl<H> !Send for HookBuilder<H>

§

impl<H> !Sync for HookBuilder<H>

§

impl<H> Unpin for HookBuilder<H>

§

impl<H> UnsafeUnpin for HookBuilder<H>

§

impl<H> !UnwindSafe for HookBuilder<H>

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.