Skip to main content

StrBuilder

Struct StrBuilder 

Source
pub struct StrBuilder { /* private fields */ }
Expand description

Where a kernel puts the bytes of the strings it makes.

A kernel that answers a number writes into a register the arena already sized for it. A kernel that answers a string has no such room, because how many bytes a chunk of answers comes to is not known until the answers are made, so the bytes go here instead and the vector’s views point back into them. Short answers never reach the buffer at all, a view of twelve bytes or fewer carrying its own payload, so a column of words costs one vector and nothing else.

The whole chunk shares one buffer, which is one allocation for a call rather than one per row, and the views hold offsets rather than pointers so the buffer may grow underneath them.

Implementations§

Source§

impl StrBuilder

Source

pub fn new() -> Self

Source

pub fn with_capacity(bytes: usize) -> Self

Room for the long answers of a chunk, when the caller can say what that comes to. An answer no longer than what it was made from is the common case, so the input’s byte count is the usual argument and the usual outcome is that the buffer never grows.

Source

pub fn push_with(&mut self, len: usize, fill: impl FnOnce(&mut [u8])) -> StrView

Room for a string of len bytes, filled by fill, answered as the view that reads it back.

The caller writes into the answer rather than handing one over, so a fold or a trim costs no working string of its own.

Source

pub fn push(&mut self, bytes: &[u8]) -> StrView

A string already in hand, copied in.

Source

pub fn finish(self) -> StrBuffers

The buffers the views this handed out read through. A chunk whose answers were all short leaves no buffer behind.

Trait Implementations§

Source§

impl Default for StrBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.