ByteCursor structv0.1.0

Source
A fixed buffer being filled from the front.
pub struct ByteCursor {
    // private fields
}

Constructors

ByteCursor

pub func ByteCursor(room: var char8[..]) -> ByteCursor

A cursor over room, filling from its start.

NameTypeDescription
roomvar char8[..]how many bytes the buffer holds

Returns: a cursor over that storage, having written nothing

Source

Methods

Push

pub func Push(self: &var ByteCursor, byte: char8)

Appends one byte, or records an overrun when there is no room.

NameTypeDescription
bytechar8the byte

Source

PushBytes

pub func PushBytes(self: &var ByteCursor, bytes: char8[..])

Appends every byte of bytes, or records an overrun when they do not all fit.

NameTypeDescription
byteschar8[..]the bytes

Source

Written

pub func Written(self: &ByteCursor) -> char8[..]

What has been written.

Returns: the bytes written so far, borrowed

Source

Overran

pub func Overran(self: &ByteCursor) -> bool

Whether a write was refused for want of room.

Returns: whether more was pushed than the buffer holds, which silently dropped the excess

Source

Implements TextWriter

ByteCursor conforms to TextWriter.

Write

pub func Write(
    self: &var ByteCursor,
    bytes: char8[..]
) -> ! FormatError

Writes bytes into the buffer. Reports InsufficientCapacity when the bytes do not all fit. The cursor is a bounded destination, so this is the failure it exists to report; a WriterFailure is impossible, since there is no destination beyond the buffer, and the bytes are not revalidated here, so no TextFailure arises either. Unlike a builder, a cursor that overruns keeps whatever fitted rather than leaving itself unchanged: the buffer is the caller's, the partial content is visible through Written, and Overran says it is partial.

NameTypeDescription
byteschar8[..]the UTF-8 run to write

Returns: success when every byte fitted

Source