Struct stam::TextResource
source · pub struct TextResource { /* private fields */ }Expand description
This holds the textual resource to be annotated. It holds the full text in memory.
The text SHOULD be in Unicode Normalization Form C (NFC) but MAY be in another unicode normalization forms.
Implementations§
source§impl TextResource
impl TextResource
sourcepub fn new(id: impl Into<String>, config: Config) -> Self
pub fn new(id: impl Into<String>, config: Config) -> Self
Instantiates a new completely empty TextResource
sourcepub fn from_file(filename: &str, config: Config) -> Result<Self, StamError>
pub fn from_file(filename: &str, config: Config) -> Result<Self, StamError>
Create a new TextResource from file, the text will be loaded into memory entirely
sourcepub fn with_string(self, text: impl Into<String>) -> Self
pub fn with_string(self, text: impl Into<String>) -> Self
Sets the text of the TextResource from string, kept in memory entirely
The use of Self::from_string() is preferred instead. This method can be dangerous
if it modifies any existing text of a resource.
sourcepub fn from_string(
id: impl Into<String>,
text: impl Into<String>,
config: Config
) -> Self
pub fn from_string( id: impl Into<String>, text: impl Into<String>, config: Config ) -> Self
Create a new TextResource from string, kept in memory entirely
sourcepub fn known_textselection(
&self,
offset: &Offset
) -> Result<Option<TextSelectionHandle>, StamError>
pub fn known_textselection( &self, offset: &Offset ) -> Result<Option<TextSelectionHandle>, StamError>
Finds a known text selection, as specified by the offset. Known textselections
are associated with an annotation. Returns a handle.
Use the higher-level method FindText::textselection() instead if you want to
return a textselection regardless of whether it’s known or not.
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, if the text selection is known, its’ handle will be set
If you don’t care about unbound textselection but only known ones, then use Self::known_textselection() instead.
sourcepub fn textselections_unsorted(&self) -> impl Iterator<Item = &TextSelection>
pub fn textselections_unsorted(&self) -> impl Iterator<Item = &TextSelection>
Low-level method returning an unsorted iterator over all textselections in this resource
Use this only if order doesn’t matter for. For a sorted version, use Self::iter() or Self::range() instead.
pub fn textselections_len(&self) -> usize
sourcepub fn range<'a>(&'a self, begin: usize, end: usize) -> TextSelectionIter<'a> ⓘ
pub fn range<'a>(&'a self, begin: usize, end: usize) -> TextSelectionIter<'a> ⓘ
Returns a sorted double-ended iterator over a range of all textselections and returns all textselections (in order) that either start or end in this range (depending on the direction you’re iterating in).
sourcepub fn iter<'a>(&'a self) -> TextSelectionIter<'a> ⓘ
pub fn iter<'a>(&'a self) -> TextSelectionIter<'a> ⓘ
Returns a sorted double-ended iterator over all textselections in this resource.
For unsorted (slightly more performant), use TextResource::textselections_unsorted() instead.
sourcepub fn positions<'a>(
&'a self,
mode: PositionMode
) -> Box<dyn Iterator<Item = &'a usize> + 'a>
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 are in use.
By passing a PositionMode parameter you can specify whether you want only positions where a textselection begins, ends or both.
sourcepub fn positions_in_range<'a>(
&'a self,
mode: PositionMode,
begin: usize,
end: usize
) -> Box<dyn Iterator<Item = &'a usize> + 'a>
pub fn positions_in_range<'a>( &'a self, mode: PositionMode, begin: usize, end: usize ) -> Box<dyn Iterator<Item = &'a usize> + 'a>
Returns a sorted iterator over all absolute positions (begin aligned cursors) that are in use within a certain range.
By passing a PositionMode parameter you can specify whether you want only positions where a textselection begins, ends or both.
sourcepub fn position(&self, index: usize) -> Option<&PositionIndexItem>
pub fn position(&self, index: usize) -> Option<&PositionIndexItem>
Lookup a position (unicode point) in the PositionIndex. Low-level function. Only works for positions at which a TextSelection starts or ends (non-inclusive), returns None otherwise
sourcepub fn positionindex_len(&self) -> usize
pub fn positionindex_len(&self) -> usize
Returns the number of positions in the positionindex
pub fn shrink_to_fit(&mut self)
Trait Implementations§
source§impl AssociatedFile for TextResource
impl AssociatedFile for TextResource
source§fn filename(&self) -> Option<&str>
fn filename(&self) -> Option<&str>
Get the filename for stand-off file specified using @include (if any)
source§fn set_filename(&mut self, filename: &str) -> &mut Self
fn set_filename(&mut self, filename: &str) -> &mut Self
Get the filename for stand-off file specified using @include (if any)
fn with_filename(self, filename: &str) -> Selfwhere
Self: Sized,
source§fn filename_without_extension(&self) -> Option<&str>
fn filename_without_extension(&self) -> Option<&str>
source§fn filename_without_workdir(&self) -> Option<&str>
fn filename_without_workdir(&self) -> Option<&str>
source§impl Clone for TextResource
impl Clone for TextResource
source§fn clone(&self) -> TextResource
fn clone(&self) -> TextResource
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Configurable for TextResource
impl Configurable for TextResource
source§impl DataSize for TextResource
impl DataSize for TextResource
source§const IS_DYNAMIC: bool = true
const IS_DYNAMIC: bool = true
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 TextResource
impl Debug for TextResource
source§impl<'bytes, Ctx> Decode<'bytes, Ctx> for TextResource
impl<'bytes, Ctx> Decode<'bytes, Ctx> for TextResource
source§impl<Ctx> Encode<Ctx> for TextResource
impl<Ctx> Encode<Ctx> for TextResource
source§impl PartialEq for TextResource
impl PartialEq for TextResource
source§fn eq(&self, other: &TextResource) -> bool
fn eq(&self, other: &TextResource) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialOrd for TextResource
impl PartialOrd for TextResource
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<TextResource> for TextResourceHandle
impl<'a> Request<TextResource> for TextResourceHandle
source§fn to_handle<'store, S>(&self, _store: &'store S) -> Option<TextResourceHandle>where
S: StoreFor<TextResource>,
fn to_handle<'store, S>(&self, _store: &'store S) -> Option<TextResourceHandle>where
S: StoreFor<TextResource>,
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 SelfSelector for TextResource
impl SelfSelector for TextResource
source§impl Serialize for TextResource
impl Serialize for TextResource
source§impl Storable for TextResource
impl Storable for TextResource
type HandleType = TextResourceHandle
type StoreHandleType = ()
type FullHandleType = <TextResource as Storable>::HandleType
type StoreType = AnnotationStore
source§fn handle(&self) -> Option<TextResourceHandle>
fn handle(&self) -> Option<TextResourceHandle>
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: TextResourceHandle) -> Self
fn with_handle(self, handle: TextResourceHandle) -> Self
source§fn carries_id() -> bool
fn carries_id() -> bool
fn fullhandle( _storehandle: Self::StoreHandleType, handle: Self::HandleType ) -> Self::FullHandleType
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<TextResource> for AnnotationStore
impl StoreFor<TextResource> for AnnotationStore
source§fn store(&self) -> &Store<TextResource>
fn store(&self) -> &Store<TextResource>
Get a reference to the entire store for the associated type
source§fn store_mut(&mut self) -> &mut Store<TextResource>
fn store_mut(&mut self) -> &mut Store<TextResource>
Get a mutable reference to the entire store for the associated type
source§fn idmap(&self) -> Option<&IdMap<TextResourceHandle>>
fn idmap(&self) -> Option<&IdMap<TextResourceHandle>>
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<TextResourceHandle>>
fn idmap_mut(&mut self) -> Option<&mut IdMap<TextResourceHandle>>
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 remove(&mut self, handle: T::HandleType) -> Result<(), StamError>
fn remove(&mut self, handle: T::HandleType) -> Result<(), 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 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 remove(&mut self, handle: T::HandleType) -> Result<(), StamError>
fn remove(&mut self, handle: T::HandleType) -> Result<(), 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<'store> Text<'store, 'store> for TextResource
impl<'store> Text<'store, 'store> for TextResource
source§fn textlen(&self) -> usize
fn textlen(&self) -> usize
Returns the length of the text in unicode points
For bytes, use self.text().len() instead.
source§fn text_by_offset(
&'store self,
offset: &Offset
) -> Result<&'store str, StamError>
fn text_by_offset( &'store self, offset: &Offset ) -> Result<&'store str, StamError>
Returns a string reference to a slice of text as specified by the offset
source§fn utf8byte(&self, abscursor: usize) -> Result<usize, StamError>
fn utf8byte(&self, abscursor: usize) -> Result<usize, StamError>
Resolves a begin aligne cursor to UTF-8 byteposition
If you have a Cursor instance, pass it through Self::beginaligned_cursor() first.
source§fn utf8byte_to_charpos(&self, bytecursor: usize) -> Result<usize, StamError>
fn utf8byte_to_charpos(&self, bytecursor: usize) -> Result<usize, StamError>
Convert utf8 byte to unicode point. O(n), not as efficient as the reverse operation in Self::utf8byte()
source§fn subslice_utf8_offset(&self, subslice: &str) -> Option<usize>
fn subslice_utf8_offset(&self, subslice: &str) -> Option<usize>
Finds the utf-8 byte position where the specified text subslice begins