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,
Text::remove_tags_on, and Text::remove_tags_of to add and
remove tags to a 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. In order to not have these different actors
interfere with eachother’s work, keys were implemented:
use duat_core::{forms, 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 = forms::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_on(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) -> Option<usize>
fn steps_between(start: &Self, end: &Self) -> Option<usize>
step_trait)Source§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)impl Copy for Key
impl Eq for Key
impl StructuralPartialEq for Key
Auto Trait Implementations§
impl Freeze for Key
impl RefUnwindSafe for Key
impl Send for Key
impl Sync for Key
impl Unpin for Key
impl UnwindSafe for Key
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)