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
impl Ns
Sourcepub const fn new_lazy() -> LazyLock<Self>
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();Sourcepub fn new_many(amount: u32) -> Range<Self>
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.
Sourcepub const fn basic() -> Self
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.