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, end offset and optionally a handle.
if the textselection is already known in the model.
This is similar to Offset, but that one uses cursors which may
be relative. TextSelection specifies 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, such as in the higher-level wrapper ResultTextSelection.
Implementations§
source§impl TextSelection
impl TextSelection
sourcepub fn relative_begin(&self, container: &TextSelection) -> Option<usize>
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.
sourcepub fn relative_end(&self, container: &TextSelection) -> Option<usize>
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.
sourcepub fn relative_offset(
&self,
container: &TextSelection,
offsetmode: OffsetMode
) -> Option<Offset>
pub fn relative_offset( &self, container: &TextSelection, offsetmode: OffsetMode ) -> 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.
sourcepub fn absolute_offset(&self, offset: &Offset) -> Result<Offset, StamError>
pub fn absolute_offset(&self, offset: &Offset) -> Result<Offset, StamError>
Converts a relative offset, expressed in the coordinates of this text selection, to an absolute one expressed in the coordinates of the resource.
sourcepub fn textselection_by_offset(
&self,
offset: &Offset
) -> Result<TextSelection, StamError>
pub fn textselection_by_offset( &self, offset: &Offset ) -> Result<TextSelection, StamError>
Low-level method to get a textselection inside the current one Note: this is a low level method and will always return an unbound textselection!
sourcepub fn to_resulttextselection<'store>(
self,
resource: &'store TextResource,
store: &'store AnnotationStore
) -> ResultTextSelection<'store>
pub fn to_resulttextselection<'store>( self, resource: &'store TextResource, store: &'store AnnotationStore ) -> ResultTextSelection<'store>
Convert this text selection to its higher level API counterpart
sourcepub fn intersection(
&self,
other: &TextSelection
) -> Option<(TextSelection, Option<TextSelection>, Option<TextSelection>)>
pub fn intersection( &self, other: &TextSelection ) -> Option<(TextSelection, Option<TextSelection>, Option<TextSelection>)>
Compute the intersection (overlap) between two text selections Returns the intersection part, self - other, other - self, as three new Text Selections. Returns none if there is no intersection at all. The text selections will not be bound to any handles.
If you merely want to test for overlap, then use test() instead.
Trait Implementations§
source§impl Clone for TextSelection
impl Clone for TextSelection
source§fn clone(&self) -> TextSelection
fn clone(&self) -> TextSelection
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl DataSize for TextSelection
impl DataSize for TextSelection
source§const IS_DYNAMIC: bool = false
const IS_DYNAMIC: bool = false
true, the type has a heap size that can vary at runtime, depending on the actual value.source§const STATIC_HEAP_SIZE: usize = 0usize
const STATIC_HEAP_SIZE: usize = 0usize
IS_DYNAMIC is false, this is
the total amount of heap memory occupied by the value. Otherwise this is a lower bound.source§fn estimate_heap_size(&self) -> usize
fn estimate_heap_size(&self) -> usize
source§impl Debug for TextSelection
impl Debug for TextSelection
source§impl<'bytes, Ctx> Decode<'bytes, Ctx> for TextSelection
impl<'bytes, Ctx> Decode<'bytes, Ctx> for TextSelection
source§impl<Ctx> Encode<Ctx> for TextSelection
impl<Ctx> Encode<Ctx> for TextSelection
source§impl Extend<TextSelection> for TextSelectionSet
impl Extend<TextSelection> for TextSelectionSet
source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = TextSelection>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = TextSelection>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)source§impl From<&TextSelection> for Offset
impl From<&TextSelection> for Offset
source§fn from(textselection: &TextSelection) -> Offset
fn from(textselection: &TextSelection) -> Offset
source§impl From<TextSelection> for Offset
impl From<TextSelection> for Offset
source§fn from(textselection: TextSelection) -> Offset
fn from(textselection: TextSelection) -> Offset
source§impl Hash for TextSelection
impl Hash for TextSelection
source§impl Ord for TextSelection
impl Ord for TextSelection
source§impl PartialEq for TextSelection
impl PartialEq for TextSelection
source§fn eq(&self, other: &TextSelection) -> bool
fn eq(&self, other: &TextSelection) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialOrd for TextSelection
impl PartialOrd for TextSelection
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<'a> Request<TextSelection> for TextSelectionHandle
impl<'a> Request<TextSelection> for TextSelectionHandle
source§fn to_handle<'store, S>(&self, _store: &'store S) -> Option<TextSelectionHandle>where
S: StoreFor<TextSelection>,
fn to_handle<'store, S>(&self, _store: &'store S) -> Option<TextSelectionHandle>where
S: StoreFor<TextSelection>,
source§fn requested_id(&self) -> Option<&str>
fn requested_id(&self) -> Option<&str>
source§fn requested_id_owned(self) -> Option<String>
fn requested_id_owned(self) -> Option<String>
source§fn requested_handle(&self) -> Option<T::HandleType>
fn requested_handle(&self) -> Option<T::HandleType>
source§impl Storable for TextSelection
impl Storable for TextSelection
type HandleType = TextSelectionHandle
type StoreHandleType = TextResourceHandle
type FullHandleType = (TextResourceHandle, TextSelectionHandle)
type StoreType = TextResource
source§fn handle(&self) -> Option<TextSelectionHandle>
fn handle(&self) -> Option<TextSelectionHandle>
StoreFor<T>, this may return None only in the initial
stage when it is still unbounded to a store, so this is almost always safe to unwrap when used in the public API.source§fn with_handle(self, handle: TextSelectionHandle) -> Self
fn with_handle(self, handle: TextSelectionHandle) -> Self
source§fn carries_id() -> bool
fn carries_id() -> bool
fn fullhandle( storehandle: Self::StoreHandleType, handle: Self::HandleType ) -> Self::FullHandleType
source§fn merge(&mut self, _other: Self) -> Result<(), StamError>
fn merge(&mut self, _other: Self) -> Result<(), StamError>
source§fn unbind(self) -> Self
fn unbind(self) -> Self
source§fn handle_or_err(&self) -> Result<Self::HandleType, StamError>
fn handle_or_err(&self) -> Result<Self::HandleType, StamError>
Self::handle() but returns a StamError::Unbound error if there is no internal id.source§fn temp_id(&self) -> Result<String, StamError>
fn temp_id(&self) -> Result<String, StamError>
source§fn as_resultitem<'store>(
&'store self,
store: &'store Self::StoreType,
rootstore: &'store AnnotationStore
) -> ResultItem<'store, Self>where
Self: Sized,
fn as_resultitem<'store>(
&'store self,
store: &'store Self::StoreType,
rootstore: &'store AnnotationStore
) -> ResultItem<'store, Self>where
Self: Sized,
T as a ResultItem<T>, i.e. a wrapped reference that includes a reference to
both this item as well as the store that owns it. All high-level API functions are implemented
on such Result types. You should not need to invoke this yourself.source§fn generate_id(self, idmap: Option<&mut IdMap<Self::HandleType>>) -> Selfwhere
Self: Sized,
fn generate_id(self, idmap: Option<&mut IdMap<Self::HandleType>>) -> Selfwhere
Self: Sized,
source§impl StoreFor<TextSelection> for TextResource
impl StoreFor<TextSelection> for TextResource
source§fn store(&self) -> &Store<TextSelection>
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>
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>>
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>>
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
fn store_typeinfo() -> &'static str
source§fn insert(&mut self, item: T) -> Result<T::HandleType, StamError>
fn insert(&mut self, item: T) -> Result<T::HandleType, StamError>
source§fn add(self, item: T) -> Result<Self, StamError>where
Self: Sized,
fn add(self, item: T) -> Result<Self, StamError>where
Self: Sized,
source§unsafe fn get_unchecked(&self, handle: T::HandleType) -> Option<&T>
unsafe fn get_unchecked(&self, handle: T::HandleType) -> Option<&T>
source§fn get(&self, item: impl Request<T>) -> Result<&T, StamError>
fn get(&self, item: impl Request<T>) -> Result<&T, StamError>
AnnotationStore::annotation() instead.source§fn get_mut(&mut self, item: impl Request<T>) -> Result<&mut T, StamError>
fn get_mut(&mut self, item: impl Request<T>) -> Result<&mut T, StamError>
source§fn resolve_id(&self, id: &str) -> Result<T::HandleType, StamError>
fn resolve_id(&self, id: &str) -> Result<T::HandleType, StamError>
source§fn iter(&self) -> StoreIter<'_, T>where
T: Storable<StoreType = Self>,
fn iter(&self) -> StoreIter<'_, T>where
T: Storable<StoreType = Self>,
annotations(), resources() instead. source§fn iter_mut(&mut self) -> StoreIterMut<'_, T>
fn iter_mut(&mut self) -> StoreIterMut<'_, T>
source§fn next_handle(&self) -> T::HandleType
fn next_handle(&self) -> T::HandleType
source§fn last_handle(&self) -> T::HandleType
fn last_handle(&self) -> T::HandleType
source§impl TestTextSelection for TextSelection
impl TestTextSelection for TextSelection
source§fn test(
&self,
operator: &TextSelectionOperator,
reftextsel: &TextSelection,
resource: &TextResource
) -> bool
fn test( &self, operator: &TextSelectionOperator, reftextsel: &TextSelection, resource: &TextResource ) -> 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§fn test_set(
&self,
operator: &TextSelectionOperator,
refset: &TextSelectionSet,
resource: &TextResource
) -> bool
fn test_set( &self, operator: &TextSelectionOperator, refset: &TextSelectionSet, resource: &TextResource ) -> 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.
source§impl TypeInfo for TextSelection
impl TypeInfo for TextSelection
impl Copy for TextSelection
impl Eq for TextSelection
impl StructuralPartialEq for TextSelection
Auto Trait Implementations§
impl Freeze for TextSelection
impl RefUnwindSafe for TextSelection
impl Send for TextSelection
impl Sync for TextSelection
impl Unpin for TextSelection
impl UnwindSafe for TextSelection
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> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more