memio+x86_64 +linux

memio provides implementations of io::stream which can read from or write to byte slices. fixed uses a caller-supplied buffer for storage, while dynamic uses a dynamically allocated buffer which will grow instead of erroring when writing past the end of the buffer. All memio streams are seekable; the read-write head works the same way as an operating system file. You can access the contents of the buffer via buffer and string.

Additionally, memio provides string-related I/O operations. 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 memio:: or bufio:: stream.

Index

Types

// Undocumented types:
type stream = struct {
	stream: io::stream,
	buf: []u8,
	pos: size,
};

Functions

fn appendrune(out: io::handle, r: rune) (size | io::error);
fn borrowedread(st: *stream, amt: size) ([]u8 | io::EOF);
fn buffer(in: *stream) []u8;
fn concat(out: io::handle, strs: str...) (size | io::error);
fn dynamic() stream;
fn dynamic_from(in: []u8) stream;
fn fixed(in: []u8) stream;
fn join(out: io::handle, delim: str, strs: str...) (size | io::error);
fn rconcat(out: io::handle, strs: str...) (size | io::error);
fn reset(in: *stream) void;
fn rjoin(out: io::handle, delim: str, strs: str...) (size | io::error);
fn string(in: *stream) (str | utf8::invalid);

Types

type stream[link]

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

Functions

fn appendrune[link]

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

Appends a rune to a stream.

fn borrowedread[link]

fn borrowedread(st: *stream, amt: size) ([]u8 | io::EOF);

Reads data from a dynamic or fixed stream and returns a slice borrowed from the internal buffer.

fn buffer[link]

fn buffer(in: *stream) []u8;

Returns a stream's buffer, up to the current cursor position. io::seek to the end first in order to return the entire buffer. The return value is borrowed from the input.

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 memio 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 an io::stream which dynamically allocates a buffer to store writes into. Seeking the stream and reading will read the written data. Calling io::close on this stream will free the buffer. If a stream's data is referenced via buffer, the stream shouldn't be closed as long as the data is used.

fn dynamic_from[link]

fn dynamic_from(in: []u8) stream;

Like dynamic, but takes an existing slice as input. Writes will overwrite the buffer and reads consume bytes from the initial buffer. Ownership of the provided slice is transferred to the returned stream. Calling io::close will free the buffer.

fn fixed[link]

fn fixed(in: []u8) stream;

Creates a stream for a fixed, caller-supplied buffer. Seeking a stream will cause subsequent writes to overwrite existing contents of the buffer. Writes return an error if they would exceed the buffer's capacity. The stream doesn't have 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 memio stream, but it's generally more efficient if it is. Returns the number of bytes written, or an error.

fn rconcat[link]

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

Appends zero or more strings to an io::handle, in reverse order. The output needn't be a memio 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;

A convenience function that sets the read-write cursor to zero, so that the buffer can be overwritten and reused.

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 memio 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 | utf8::invalid);

Returns a stream's buffer, up to the current cursor position, as a string. io::seek to the end first in order to return the entire buffer. The return value is borrowed from the input.