Skip to main content

Ns

Struct Ns 

Source
pub struct Ns(/* private fields */);
Expand description

A namespace for Duat operations.

This is a unique identifier which makes sure you’re only affecting the parts of Duat that you want to affect. It is used in various places within duat:

Here’s an example of a namespace being used to add Tags to Text:

let mut text = txt!("This is text with no tags in it");
// This key will be used to modify text.
let ns1 = Ns::new();

let id = form::id_of!("invisible");

// You can create an `impl Tag` directly from a `FormId`
text.insert_tag(ns1, 18..20, id.to_tag(0));

assert_eq!(text, txt!("This is text with [invisible]no[] tags in it"));

// ns2 != ns1, so it shouldn't be able to change what was done with ns1.
let ns2 = Ns::new();
text.remove_tags(ns2, 18);

assert_eq!(text, txt!("This is text with [invisible]no[] tags in it"));

Implementations§

Source§

impl Ns

Source

pub fn new() -> Self

Returns a new, unique namespace.

Source

pub const fn new_lazy() -> LazyLock<Self>

Returns a new LazyLock<Ns>.

You can use this in order to create static namespaces by calling something like:

use std::sync::LazyLock;

use duat::prelude::*;

static NS: LazyLock<Ns> = Ns::new_lazy();
Source

pub fn new_many(amount: u32) -> Range<Self>

Returns a number of new, unique namespaces

You may want to do this if you expect to be placing and removing a lot of tags, and you want the finest possible control over what gets added and deleted from the Text.

Source

pub const fn basic() -> Self

A simple key with no uniqueness guarantee

You should use this if you’re editing widgets that are not the Buffer widget, since you’re probably the only one that is going to be modifying said widget anyway.

The advantage of this function is speed. Since it is a const function, it’s value is just substituted in with the code, so there is no need to store it in structs or statics.

Trait Implementations§

Source§

impl<'__de, __Context> BorrowDecode<'__de, __Context> for Ns

Source§

fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>

Attempt to decode this type with the given BorrowDecode.
Source§

impl Clone for Ns

Source§

fn clone(&self) -> Ns

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 Ns

Source§

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

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

impl<__Context> Decode<__Context> for Ns

Source§

fn decode<__D: Decoder<Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>

Attempt to decode this type with the given Decode.
Source§

impl Default for Ns

Source§

fn default() -> Self

Returns a new namespace.

Not to be confused with Ns::basic.

Source§

impl Encode for Ns

Source§

fn encode<__E: Encoder>(&self, encoder: &mut __E) -> Result<(), EncodeError>

Encode a given type.
Source§

impl Hash for Ns

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Ns

Source§

fn cmp(&self, other: &Ns) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Ns

Source§

fn eq(&self, other: &Ns) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Ns

Source§

fn partial_cmp(&self, other: &Ns) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Ns

Source§

impl Eq for Ns

Source§

impl StructuralPartialEq for Ns

Auto Trait Implementations§

§

impl Freeze for Ns

§

impl RefUnwindSafe for Ns

§

impl Send for Ns

§

impl Sync for Ns

§

impl Unpin for Ns

§

impl UnsafeUnpin for Ns

§

impl UnwindSafe for Ns

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> TryClone for T
where T: Clone,

Source§

fn try_clone(&self) -> Result<T, Error>

Clones self, possibly returning an error.
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.