Struct stam::TextSelection

source ·
pub struct TextSelection { /* private fields */ }
Expand description

Corresponds to a slice of the text. This only contains minimal information; i.e. the begin offset and end offset. This is similar to Offset, but that one uses cursors which may be relative. TextSelection specified an offset in more absolute terms.

The actual reference to the crate::TextResource is not stored in this structure but should accompany it explicitly when needed

On the lowest-level, this struct is obtain by a call to crate::annotationstore::AnnotationStore::textselection(), which resolves a crate::Selector::TextSelector to a TextSelection. Such calls are often abstracted away by higher level methods such as [crate::annotationstore::AnnotationStore::textselections_by_annotation()].

Implementations§

source§

impl TextSelection

source

pub fn begin(&self) -> usize

Return the begin position (unicode points)

source

pub fn end(&self) -> usize

Return the end position (non-inclusive) in unicode points

source

pub fn relative_begin(&self, container: &TextSelection) -> Option<usize>

Returns the begin cursor of this text selection in another. Returns None if they are not embedded. Note: this does NOT check whether the textselections pertain to the same resource, that is up to the caller.

source

pub fn relative_end(&self, container: &TextSelection) -> Option<usize>

Returns the end cursor (begin-aligned) of this text selection in another. Returns None if they are not embedded. Note: this does NOT check whether the textselections pertain to the same resource, that is up to the caller.

source

pub fn relative_offset(&self, container: &TextSelection) -> Option<Offset>

Returns the offset of this text selection in another. Returns None if they are not embedded. Note: this does NOT check whether the textselections pertain to the same resource, that is up to the caller.

source§

impl TextSelection

source

pub fn test( &self, operator: &TextSelectionOperator, reftextsel: &TextSelection ) -> bool

This method is called to test whether a specific spatial relation (as expressed by the passed operator) holds between a TextSelection and another. A boolean is returned with the test result.

source

pub fn test_set( &self, operator: &TextSelectionOperator, refset: &TextSelectionSet ) -> bool

This method is called to test whether a specific spatial relation (as expressed by the passed operator) holds between a TextSelection and another (or multiple) (TextSelectionSet). The operator contains the other part of the equation that is tested against. A boolean is returned with the test result.

Trait Implementations§

source§

impl Clone for TextSelection

source§

fn clone(&self) -> TextSelection

Returns a copy 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 TextSelection

source§

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

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

impl Extend<TextSelection> for TextSelectionSet

source§

fn extend<T>(&mut self, iter: T)where T: IntoIterator<Item = TextSelection>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl From<&TextSelection> for Offset

source§

fn from(textselection: &TextSelection) -> Offset

Converts to this type from the input type.
source§

impl Hash for TextSelection

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 TextSelection

source§

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

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

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

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

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

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

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

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

impl PartialEq<TextSelection> for TextSelection

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<TextSelection> for TextSelection

source§

fn partial_cmp(&self, other: &Self) -> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Storable for TextSelection

§

type HandleType = TextSelectionHandle

§

type StoreType = TextResource

source§

fn id(&self) -> Option<&str>

Get the public ID
source§

fn handle(&self) -> Option<TextSelectionHandle>

Retrieve the internal (numeric) id. For any type T uses in StoreFor<T>, this may be None only in the initial stage when it is still unbounded to a store.
source§

fn set_handle(&mut self, handle: TextSelectionHandle)

Set the internal ID. May only be called once (though currently not enforced).
source§

fn carries_id() -> bool

Does this type support an ID?
source§

fn handle_or_err(&self) -> Result<Self::HandleType, StamError>

Like Self::handle() but returns a StamError::Unbound error if there is no internal id.
source§

fn id_or_err(&self) -> Result<&str, StamError>

Like Self::id() but returns a StamError::NoIdError error if there is no internal id.
source§

fn with_id(self, id: String) -> Selfwhere Self: Sized,

Builder pattern to set the public Id
source§

fn wrap_in<'store>( &'store self, store: &'store Self::StoreType ) -> Result<WrappedItem<'store, Self>, StamError>where Self: Sized,

Returns a wrapped reference to this item and the store that owns it. This allows for some more introspection on the part of the item. reverse of StoreFor<T>::wrap()
source§

fn wrap_owned_in<'store>( self, store: &'store Self::StoreType ) -> Result<WrappedItem<'store, Self>, StamError>where Self: Sized,

Returns a wrapped reference to this item and the store that owns it. This allows for some more introspection on the part of the item. reverse of StoreFor<T>::wrap_owned()
source§

fn bound(&mut self)

Callback function that is called after an item is bound to a store
source§

fn generate_id(self, idmap: Option<&mut IdMap<Self::HandleType>>) -> Selfwhere Self: Sized,

Generate a random ID in a given idmap (adds it to the map and assigns it to the item)
source§

impl StoreFor<TextSelection> for TextResource

source§

fn store(&self) -> &Store<TextSelection>

Get a reference to the entire store for the associated type

source§

fn store_mut(&mut self) -> &mut Store<TextSelection>

Get a mutable reference to the entire store for the associated type

source§

fn idmap(&self) -> Option<&IdMap<TextSelectionHandle>>

Get a reference to the id map for the associated type, mapping global ids to internal ids

source§

fn idmap_mut(&mut self) -> Option<&mut IdMap<TextSelectionHandle>>

Get a mutable reference to the id map for the associated type, mapping global ids to internal ids

source§

fn store_typeinfo() -> &'static str

source§

fn inserted(&mut self, handle: TextSelectionHandle) -> Result<(), StamError>

Called after an item was inserted to the store Allows the store to do further bookkeeping like updating relation maps
source§

fn insert(&mut self, item: T) -> Result<T::HandleType, StamError>

Adds an item to the store. Returns a handle to it upon success.
source§

fn preinsert(&self, item: &mut T) -> Result<(), StamError>

Called prior to inserting an item into to the store If it returns an error, the insert will be cancelled. Allows for bookkeeping such as inheriting configuration parameters from parent to the item
source§

fn add(self, item: T) -> Result<Self, StamError>where Self: Sized,

source§

fn has<'a, 'b>(&'a self, item: &Item<'b, T>) -> bool

Returns true if the store has the item
source§

unsafe fn get_unchecked(&self, handle: T::HandleType) -> Option<&T>

Get a reference to an item from the store, by handle, without checking validity. Read more
source§

fn get<'a, 'b>(&'a self, item: &Item<'b, T>) -> Result<&'a T, StamError>

Get a reference to an item from the store
source§

fn get_mut<'a, 'b>(&mut self, item: &Item<'b, T>) -> Result<&mut T, StamError>

Get a mutable reference to an item from the store by internal ID
source§

fn remove(&mut self, handle: T::HandleType) -> Result<(), StamError>

Removes an item by handle, returns an error if the item has dependencies and can’t be removed
source§

fn preremove(&mut self, handle: T::HandleType) -> Result<(), StamError>

Called before an item is removed from the store Allows the store to do further bookkeeping like updating relation maps
source§

fn resolve_id(&self, id: &str) -> Result<T::HandleType, StamError>

Resolves an ID to a handle You usually don’t want to call this directly
source§

fn owns(&self, item: &T) -> Option<bool>

Tests if the item is owner by the store, returns None if ownership is unknown
source§

fn iter<'a>(&'a self) -> StoreIter<'a, T> where T: Storable<StoreType = Self>,

Iterate over the store
source§

fn iter_mut<'a>(&'a mut self) -> StoreIterMut<'a, T>

Iterate over the store, mutably
source§

fn next_handle(&self) -> T::HandleType

Return the internal id that will be assigned for the next item to the store
source§

fn last_handle(&self) -> T::HandleType

Return the internal id that was assigned to last inserted item
source§

fn bind(&mut self, item: T) -> Result<T, StamError>

This binds an item to the store PRIOR to it being actually added You should never need to call this directly (it can only be called once per item anyway).
source§

fn wrap<'a>(&'a self, item: &'a T) -> Result<WrappedItem<'_, T>, StamError>where T: Storable<StoreType = Self>,

Wraps the item in a smart pointer that also holds a reference to this store This method performs some extra checks to verify if the item is indeed owned by the store and returns an error if not.
source§

fn wrap_owned<'a>(&'a self, item: T) -> Result<WrappedItem<'_, T>, StamError>where T: Storable<StoreType = Self>,

Wraps the item in a smart pointer that also holds a reference to this store Ownership is retained with this method, i.e. the store does NOT own the item.
source§

fn wrap_store<'a>(&'a self) -> WrappedStore<'_, T, Self>where Self: Sized,

Wraps the entire store along with a reference to self Low-level method that you won’t need
source§

impl TypeInfo for TextSelection

source§

impl Copy for TextSelection

source§

impl Eq for TextSelection

source§

impl StructuralEq for TextSelection

source§

impl StructuralPartialEq for TextSelection

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V