[−][src]Struct kul::text::chunk::PosStrish
A TextChunk
implementation for boxed (heap allocated) string values,
termed "string-ish" throughout this crate, used distinctly as chunks. This
is useful for strings produced from streaming sources that buffered into one
or more strings separated at possibly arbitrary points.
This is designed to generically support various boxed string types with
shared ownership, e.g. Rc<String>
, Arc<str>
, Rc<Box<str>>
, termed
"reference-counted string-ish" types. The set of such types allowed is
those types that already implement the sealed RefCntStrish
trait. This
design allows users to choose what trade-offs of convenience and efficiency
they want between these allowed types. Shared ownership, i.e. Rc
or
Arc
, is required because this avoids copying string contents, achieving
zero-copy operations, once initially buffered or copied into a
reference-counted string-ish, i.e. RefCntStrish
-implementing, value.
The character position information this provides is only the position of
each char
relative to the start of the stream, because this does not
concern itself with what byte encoding or other position information, if
any, the streamed source might have had.
This is not intended for streaming sources that have richer position
information that is desired to be preserved. For those, a dedicated
implementation of TextChunk
should be made instead.
This is not intended for single string values that are an entire input for
parsing. For that, PosStr
(as the Chunk
type of some Text
type)
should be used instead because it provides faster zero-copy operations as
well as byte position information.
Note: The comparison traits are not implemented intentionally, because this is intended as a chunk type and comparing those directly shouldn't be done.
Fields
val: RefCntSlice<S>
The represented heap-allocated string. The RefCntSlice
type is
private but it implements AsRef<str>
and so can be used as &str
.
pos: CharPos
The char
position of the start of our string relative to its original
source.
Methods
impl<S> PosStrish<S> where
S: RefCntStrish,
[src]
S: RefCntStrish,
pub fn new(refcnt_strish: S, pos: CharPos) -> Self
[src]
Given an Rc
- or Arc
-boxed string and its position relative to its
original source, make a new chunk that represents this and can be used
with Text
types.
Trait Implementations
impl<'s, S> From<&'s str> for PosStrish<S> where
S: RefCntStrish,
[src]
S: RefCntStrish,
impl<S: Clone> Clone for PosStrish<S>
[src]
fn clone(&self) -> PosStrish<S>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<S: Debug> Debug for PosStrish<S>
[src]
impl<S> TextChunk for PosStrish<S> where
S: RefCntStrish,
[src]
S: RefCntStrish,
type CharsSrcStrm = PosStrishIter<S>
Our chunk::SourceStream
type.
fn src_strm(&self) -> Self::CharsSrcStrm
[src]
impl<S> SourceStream<PosStrish<S>> for PosStrishIter<S> where
S: RefCntStrish,
[src]
S: RefCntStrish,
Enables PosStrish
to be used as the Chunk
type of Text
types that
implement TextConcat
so they can be iterated with
kul_core::SourceStream
. A chunk::SourceStream
can accumulate what it
iterates within a single chunk. This records and grows a slice range and
creates a new chunk representing that, which shares ownership of the
original string, for each accumulation, which is zero-copy.
fn peek(&mut self) -> Option<&Self::Item>
[src]
fn next_accum(&mut self) -> Option<Self::Item>
[src]
fn accum_done(&mut self) -> PosStrish<S>
[src]
impl<S> TextBase for PosStrish<S> where
S: RefCntStrish,
[src]
S: RefCntStrish,
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,