pub struct SelectionSet { /* private fields */ }Expand description
A selection set. Always non-empty. Index primary points at the primary
selection; in v1 the set has exactly one entry and primary == 0.
The fields are private so the invariant cannot be broken: every
constructor yields at least one selection and an in-range primary, so
Self::primary never panics.
§Examples
use lattice_protocol::{Position, Selection, SelectionSet};
let mut set = SelectionSet::default(); // one cursor at the origin
assert_eq!(set.all().len(), 1);
assert_eq!(set.primary().head, Position::ZERO);
set.replace_primary(Selection::cursor(Position::new(3, 0)));
assert_eq!(set.primary().head.line, 3);
// Rebuilding from parts repairs what would break the invariant.
let repaired = SelectionSet::from_parts(vec![], 5);
assert_eq!(repaired, SelectionSet::cursor_at_origin());
let clamped = SelectionSet::from_parts(vec![Selection::cursor(Position::ZERO)], 5);
assert_eq!(clamped.primary_index(), 0);Implementations§
Source§impl SelectionSet
impl SelectionSet
Sourcepub fn cursor_at_origin() -> Self
pub fn cursor_at_origin() -> Self
One plain cursor at Position::ZERO — also the Default.
Sourcepub fn from_parts(selections: Vec<Selection>, primary: usize) -> Self
pub fn from_parts(selections: Vec<Selection>, primary: usize) -> Self
Reconstruct a set from its parts — the counterpart to Self::all +
Self::primary_index, used to rebuild a SelectionSet that was
projected into an owned form (e.g. the plugin-host WIT boundary). The
non-empty invariant is preserved: an empty selections collapses to a
single origin cursor, and primary is clamped into range.
Sourcepub fn primary(&self) -> &Selection
pub fn primary(&self) -> &Selection
The primary selection — the one single-cursor code acts on.
Sourcepub fn primary_mut(&mut self) -> &mut Selection
pub fn primary_mut(&mut self) -> &mut Selection
Mutable access to the primary selection.
Sourcepub fn primary_index(&self) -> usize
pub fn primary_index(&self) -> usize
Index of the primary within Self::all.
Sourcepub fn replace_primary(&mut self, selection: Selection)
pub fn replace_primary(&mut self, selection: Selection)
Overwrite the primary selection in place; the others are untouched.
Trait Implementations§
Source§impl Clone for SelectionSet
impl Clone for SelectionSet
Source§fn clone(&self) -> SelectionSet
fn clone(&self) -> SelectionSet
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SelectionSet
impl Debug for SelectionSet
Source§impl Default for SelectionSet
impl Default for SelectionSet
Source§impl<'de> Deserialize<'de> for SelectionSet
impl<'de> Deserialize<'de> for SelectionSet
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for SelectionSet
Source§impl PartialEq for SelectionSet
impl PartialEq for SelectionSet
Source§impl Serialize for SelectionSet
impl Serialize for SelectionSet
impl StructuralPartialEq for SelectionSet
Auto Trait Implementations§
impl Freeze for SelectionSet
impl RefUnwindSafe for SelectionSet
impl Send for SelectionSet
impl Sync for SelectionSet
impl Unpin for SelectionSet
impl UnsafeUnpin for SelectionSet
impl UnwindSafe for SelectionSet
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.