pub enum ResultTextSelection<'store> {
    Bound(ResultItem<'store, TextSelection>),
    Unbound(&'store AnnotationStore, &'store TextResource, TextSelection),
}
Expand description

This structure holds a TextSelection, along with references to its TextResource and the AnnotationStore and provides a high-level API on it.

The text selection may either be bound, in which case it corresponds to a known/existing text selection and carries a handle, or unbound, in which case it is an arbitrary textselection.

Variants§

§

Bound(ResultItem<'store, TextSelection>)

§

Unbound(&'store AnnotationStore, &'store TextResource, TextSelection)

Implementations§

source§

impl<'store> ResultTextSelection<'store>

source

pub fn inner(&self) -> &TextSelection

Return a reference to the inner textselection. This works in all cases but will have a limited lifetime. Use Self::as_ref() instead if you have bound item.

source

pub fn as_ref(&self) -> Option<&'store TextSelection>

Return a reference to the textselection in the store, with the appropriate lifetime. Only works on bound items. Use Self::inner() instead if you want something that always works.

source

pub fn as_resultitem(&self) -> Option<&ResultItem<'store, TextSelection>>

Return a reference to the textselection in the store. Only works on bound items.

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: &ResultTextSelection<'store> ) -> Option<usize>

Returns the begin cursor of this text selection in another. Returns None if they are not embedded. This also checks whether the textselections pertain to the same resource. Returns None otherwise.

source

pub fn relative_end( &self, container: &ResultTextSelection<'store> ) -> Option<usize>

Returns the end cursor (begin-aligned) of this text selection in another. Returns None if they are not embedded. This also checks whether the textselections pertain to the same resource. Returns None otherwise.

source

pub fn relative_offset( &self, container: &ResultTextSelection<'store>, offsetmode: OffsetMode ) -> Option<Offset>

Returns the offset of this text selection in another. Returns None if they are not embedded. This also checks whether the textselections pertain to the same resource. Returns None otherwise.

source

pub fn rootstore(&self) -> &'store AnnotationStore

Return the AnnotationStore this text selection references.

source

pub fn resource(&self) -> ResultItem<'store, TextResource>

Return the resource (ResultItem<TextResource>) this text selection references.

source

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

Returns the internal handle used by the TextSelection. If the TextSelection is unbound, this will return None by definition.

source

pub fn take(self) -> Result<TextSelection, StamError>

Takes ownership of the TextSelection, only works on unbound items, returns an error otherwise.

source

pub fn annotations( &self ) -> ResultIter<impl Iterator<Item = ResultItem<'store, Annotation>>>

Iterates over all annotations that are referenced by this TextSelection, if any. For unbound selections, this returns an empty iterator by definition.

source

pub fn annotations_len(&self) -> usize

Returns the number of annotations that reference this text selection For unbound selections, this is always 0.

source

pub fn related_text( &self, operator: TextSelectionOperator ) -> impl Iterator<Item = ResultTextSelection<'store>>

Applies a TextSelectionOperator to find all other text selections that are in a specific relation with the current one. Returns an iterator over the TextSelection instances. If you are interested in the annotations associated with the found text selections, then append .annotations().

source

pub fn positions<'a>( &'a self, mode: PositionMode ) -> Box<dyn Iterator<Item = &'a usize> + 'a>

Returns a sorted iterator over all absolute positions (begin aligned cursors) that overlap with this textselection and are in use in the underlying resource. By passing a PositionMode parameter you can specify whether you want only positions where a textselection begins, ends or both. This is a low-level function. Consider using .related_text(TextSelectionOperator::overlaps()) instead.

Trait Implementations§

source§

impl<'store> Clone for ResultTextSelection<'store>

source§

fn clone(&self) -> ResultTextSelection<'store>

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<'store> Debug for ResultTextSelection<'store>

source§

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

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

impl<'store, 'slf> FindText<'store, 'slf> for ResultTextSelection<'store>
where 'store: 'slf,

source§

fn find_text_regex<'regex>( &'slf self, expressions: &'regex [Regex], precompiledset: Option<&RegexSet>, allow_overlap: bool ) -> Result<FindRegexIter<'store, 'regex>, StamError>

Searches the text using one or more regular expressions, returns an iterator over TextSelections along with the matching expression, this is held by the FindRegexMatch struct.

Passing multiple regular expressions at once is more efficient than calling this function anew for each one. If capture groups are used in the regular expression, only those parts will be returned (the rest is context). If none are used, the entire expression is returned.

An offset can be specified to work on a sub-part rather than the entire text (like an existing TextSelection).

The allow_overlap parameter determines if the matching expressions are allowed to overlap. It you are doing some form of tokenisation, you also likely want this set to false. All of this only matters if you supply multiple regular expressions.

Results are returned in the exact order they are found in the text

source§

fn find_text<'fragment>( &'slf self, fragment: &'fragment str ) -> FindTextIter<'store, 'fragment>

Searches for the specified text fragment. Returns an iterator to iterate over all matches in the text. The iterator returns TextSelection items.

For more complex and powerful searching use FindText::find_text_regex() instead

If you want to search only a subpart of the text, extract a TextSelection first and then run [self.find_text()] on that instead.

source§

fn find_text_nocase(&'slf self, fragment: &str) -> FindNoCaseTextIter<'store>

Searches for the specified text fragment. Returns an iterator to iterate over all matches in the text. The iterator returns TextSelection items.

This search is case insensitive, use FindText::find_text() to search case sensitive. This variant is slightly less performant than the exact variant. For more complex and powerful searching use FindText::find_text_regex() instead

If you want to search only a subpart of the text, extract a TextSelection first with FindText::textselection() and then run FindText::find_text_nocase() on that instead.

source§

fn textselection( &'slf self, offset: &Offset ) -> Result<ResultTextSelection<'store>, StamError>

Returns a TextSelection that corresponds to the offset WITHIN the textselection. This returns a TextSelection with absolute coordinates in the resource.

If the textselection is known (i.e. it has associated annotations), it will be returned as such with a handle (borrowed). If it doesn’t exist yet, a new one will be returned, and it won’t have a handle, nor will it be added to the store automatically.

The TextSelection is returned as in a far pointer (ResultTextSelection) that also contains reference to the underlying store (the TextResource).

source§

fn split_text<'b>(&'slf self, delimiter: &'b str) -> SplitTextIter<'store, 'b>

Returns an iterator of TextSelection instances that represent partitions of the text given the specified delimiter. No text is modified. Read more
source§

fn find_text_sequence<'fragment, F>( &'slf self, fragments: &'fragment [&'fragment str], allow_skip_char: F, case_sensitive: bool ) -> Option<Vec<ResultTextSelection<'store>>>
where F: Fn(char) -> bool,

Searches for the multiple text fragment in sequence. Returns a vector with TextSelection instances wrapped as ResultTextSelection. Read more
source§

fn trim_text( &'slf self, chars: &[char] ) -> Result<ResultTextSelection<'store>, StamError>

Trims all occurrences of any character in chars from both the beginning and end of the text, returning a smaller TextSelection (as a fat pointer ResultTextSelection). No text is modified.
source§

fn trim_text_with<F>( &'slf self, f: F ) -> Result<ResultTextSelection<'store>, StamError>
where F: Fn(char) -> bool,

Trims all occurrences of any character chars that pass the supplied function, from both the beginning and end of the text, returning a smaller TextSelection (as a fat pointer ResultTextSelection). No text is modified.
source§

impl From<&ResultTextSelection<'_>> for Offset

source§

fn from(textselection: &ResultTextSelection<'_>) -> Offset

Converts to this type from the input type.
source§

impl<'store> From<ResultItem<'store, TextSelection>> for ResultTextSelection<'store>

source§

fn from(textselection: ResultItem<'store, TextSelection>) -> Self

Converts to this type from the input type.
source§

impl<'store> From<ResultTextSelection<'store>> for TextSelectionSet

source§

fn from(textselection: ResultTextSelection<'store>) -> Self

Converts to this type from the input type.
source§

impl<'store> FromIterator<ResultTextSelection<'store>> for TextSelectionSet

source§

fn from_iter<T: IntoIterator<Item = ResultTextSelection<'store>>>( iter: T ) -> Self

Creates a value from an iterator. Read more
source§

impl<'store> PartialEq for ResultTextSelection<'store>

source§

fn eq(&self, other: &Self) -> 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<'store> PartialOrd for ResultTextSelection<'store>

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<'store, 'slf> Text<'store, 'slf> for ResultTextSelection<'store>
where 'store: 'slf,

source§

fn text_by_offset(&'slf self, offset: &Offset) -> Result<&'store str, StamError>

Returns a string reference to a slice of text as specified by the offset

source§

fn subslice_utf8_offset(&self, subslice: &str) -> Option<usize>

Finds the utf-8 byte position where the specified text subslice begins The returned offset is relative to the TextSelection

source§

fn utf8byte(&self, abscursor: usize) -> Result<usize, StamError>

This converts a unicode point to utf-8 byte, all in relative offsets to this textselection

source§

fn utf8byte_to_charpos(&self, bytecursor: usize) -> Result<usize, StamError>

This converts utf-8 byte to charpos, all in relative offsets to this textselection

source§

fn text(&'slf self) -> &'store str

Returns a reference to the text
source§

fn textlen(&self) -> usize

Returns the length of the text in unicode points For bytes, use Self::text().len() instead.
source§

fn absolute_cursor(&self, cursor: usize) -> usize

Resolves a begin-aligned cursor to an absolute cursor (i.e. relative to the TextResource).
source§

fn is_empty(&'slf self) -> bool

source§

fn absolute_offset(&'slf self, offset: &Offset) -> Result<Offset, StamError>

Resolves a relative offset (relative to another TextSelection) to an absolute one (in terms of to the underlying TextResource)
source§

fn beginaligned_cursor(&'slf self, cursor: &Cursor) -> Result<usize, StamError>

Resolves a cursor to a begin aligned cursor, resolving all relative end-aligned positions

Auto Trait Implementations§

§

impl<'store> RefUnwindSafe for ResultTextSelection<'store>

§

impl<'store> Send for ResultTextSelection<'store>

§

impl<'store> Sync for ResultTextSelection<'store>

§

impl<'store> Unpin for ResultTextSelection<'store>

§

impl<'store> UnwindSafe for ResultTextSelection<'store>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<'store, I> SortTextualOrder<ResultTextSelection<'store>> for I
where I: Iterator<Item = ResultTextSelection<'store>>,

source§

fn textual_order(&mut self) -> Vec<ResultTextSelection<'store>>

Sorts items in the iterator in textual order, meaningthat items are returned in the same order as they appear in the original text. items that do not relate to text at all will be put at the end with arbitrary sorting This method allocates and returns a buffer to do the sorting. Read more
source§

impl<T> ToOwned for T
where 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 T
where 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 T
where 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 T
where V: MultiLane<T>,

§

fn vzip(self) -> V