strio +linux +x86_64

strio provides string-related I/O operations, specifically to make efficient use of memory while building strings incrementally. The main entry points to strio are dynamic and fixed. Each of the utility functions (e.g. appendrune) work correctly with any io::handle, but for efficiency reasons it is recommended that they are either a strio or bufio stream.

Index

Types

// Undocumented types:
type stream;

Functions

fn appendrune(io::handle, rune) (size | io::error);
fn concat(io::handle, str...) (size | io::error);
fn dynamic() stream;
fn fixed([]u8) stream;
fn join(io::handle, str, str...) (size | io::error);
fn reset(*stream) void;
fn rjoin(io::handle, str, str...) (size | io::error);
fn string(*stream) str;
fn truncate(*stream) void;

Types

type stream[link]

Show undocumented member
type stream = struct {
	stream: io::stream,
	buf: []u8,
};

Functions

fn appendrune[link]

fn appendrune(out: io::handle, r: rune) (size | io::error);

Appends a rune to a stream.

fn concat[link]

fn concat(out: io::handle, strs: str...) (size | io::error);

Appends zero or more strings to an io::handle. The output needn't be a strio stream, but it's generally more efficient if it is. Returns the number of bytes written, or an error.

fn dynamic[link]

fn dynamic() stream;

Creates a write-only string stream using an allocated buffer for storage, for efficiently building strings.

Calling io::close on this stream will free the buffer.

fn fixed[link]

fn fixed(in: []u8) stream;

Creates a write-only string stream using the provided buffer for storage. The program aborts if writes would exceed the buffer's capacity. The stream doesn't need to be closed.

fn join[link]

fn join(out: io::handle, delim: str, strs: str...) (size | io::error);

Joins several strings together by a delimiter and writes them to a handle. The output needn't be a strio stream, but it's generally more efficient if it is. Returns the number of bytes written, or an error.

fn reset[link]

fn reset(in: *stream) void;

Resets the buffer's length to zero, but does not attempt to deallocate its backing memory. Suitable for use both with fixed and dynamic streams.

fn rjoin[link]

fn rjoin(out: io::handle, delim: str, strs: str...) (size | io::error);

Joins several strings together by a delimiter and writes them to a handle, in reverse order. The output needn't be a strio stream, but it's generally more efficient if it is. Returns the number of bytes written, or an error.

fn string[link]

fn string(in: *stream) str;

Returns the current contents of the buffer as a string. Aborts the program if invalid UTF-8 has been written to the buffer. The return value is borrowed from the stream, and will be freed when the stream is closed. Use strings::dup to extend its lifetime.

fn truncate[link]

fn truncate(in: *stream) void;

Truncates the buffer, freeing memory associated with it and setting its length to zero.