pub struct Key(/* private fields */);Expand description
A key letting one add and remove Tags to a Text
With keys, you can use the methods Text::insert_tag and,
Text::remove_tags to add and remove Tags on the Text.
The reason why keys exist is mainly for the sake of File
widgets. In files, it is very expected that there will be many
different sources of modifiers, which can add and remove tags on
their own accord. Keys exist so that these actors don’t interfere
with eachother’s work:
use duat_core::{form, text::{text, Key, Tag}};
let mut text = text!("This is text with no tags in it");
// This key will be used to modify text.
let key1 = Key::new();
let id = form::id_of!("Invisible");
text.insert_tag(18, Tag::PushForm(id), key1);
text.insert_tag(21, Tag::PopForm(id), key1);
assert_eq!(
text,
text!("This is text with " [Invisible] "no " [] "tags in it")
);
// key2 != key, so it shouldn't be able to change what key1 has done.
let key2 = Key::new();
text.remove_tags(17, key2);
assert_eq!(
text,
text!("This is text with " [Invisible] "no " [] "tags in it")
);Implementations§
Source§impl Key
impl Key
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
File 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 has 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 Ord for Key
impl Ord for Key
Source§impl PartialOrd for Key
impl PartialOrd for Key
Source§impl Step for Key
impl Step for Key
Source§fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>)
fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>)
step_trait)start to end
like Iterator::size_hint(). Read moreSource§fn forward_checked(start: Self, count: usize) -> Option<Self>
fn forward_checked(start: Self, count: usize) -> Option<Self>
step_trait)Source§fn backward_checked(start: Self, count: usize) -> Option<Self>
fn backward_checked(start: Self, count: usize) -> Option<Self>
step_trait)Source§fn forward(start: Self, count: usize) -> Self
fn forward(start: Self, count: usize) -> Self
step_trait)Source§unsafe fn forward_unchecked(start: Self, count: usize) -> Self
unsafe fn forward_unchecked(start: Self, count: usize) -> Self
step_trait)Source§fn backward(start: Self, count: usize) -> Self
fn backward(start: Self, count: usize) -> Self
step_trait)Source§unsafe fn backward_unchecked(start: Self, count: usize) -> Self
unsafe fn backward_unchecked(start: Self, count: usize) -> Self
step_trait)