[][src]Struct kul::text::chunk::PosStrish

pub struct PosStrish<S> {
    pub val: RefCntSlice<S>,
    pub pos: CharPos,
}

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]

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]

impl<S: Clone> Clone for 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]

type CharsSrcStrm = PosStrishIter<S>

Our chunk::SourceStream type.

impl<S> SourceStream<PosStrish<S>> for PosStrishIter<S> where
    S: RefCntStrish
[src]

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.

impl<S> TextBase for PosStrish<S> where
    S: RefCntStrish
[src]

type Pos = CharPos

Positional information used with our chunks and chars.

Auto Trait Implementations

impl<S> Send for PosStrish<S> where
    S: Send

impl<S> Sync for PosStrish<S> where
    S: Sync

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]