streams.primitives

A collection of compile-time functions to help in identifying stream types and related flavors of them.

Streams come in two main flavors: input and output streams.

Input streams are defined by the presence of a read function:

StreamResult readFromStream(DataType[] buffer)

Output streams are defined by the presence of a write function:

StreamResult writeToStream(DataType[] buffer)

Usually these functions can be used as Template Constraints when defining your own functions and symbols to work with streams.

void useBytes(S)(S stream) if (isInputStream!(S, ubyte)) {
    ubyte[8192] buffer;
    StreamResult result = stream.readFromStream(buffer);
    if (!result.hasError) {
      // Do something with the data.
    }
}

Members

Aliases

OptionalStreamError
alias OptionalStreamError = Optional!StreamError

A convenience alias for an optional stream error, which is a common return type for many stream methods.

StreamResult
alias StreamResult = Either!(uint, "count", StreamError, "error")

Either a number of items that have been read or written, or a stream error, as a common result type for many stream operations.

Functions

isByteInputStream
bool isByteInputStream()

Determines if the given stream type is an input stream for ubyte elements.

isByteOutputStream
bool isByteOutputStream()

Determines if the given stream type is an output stream for ubyte elements.

isClosableStream
bool isClosableStream()

Determines if the given template argument is a closable stream type, which defines a Optional!StreamError closeStream() method as a means to close and/or deallocate the underlying resource that the stream reads from or writes to.

isFlushableStream
bool isFlushableStream()

Determines if the given template argument is a flushable stream type, which is any output stream that defines a Optional!StreamError flushStream() method, which should cause any data buffered by the stream or its resources to be flushed. The exact nature of how a flush operates is implementation- dependent.

isInputStream
bool isInputStream()

Determines if the given stream type is an input stream for reading data of the given type.

isNonPointerStream
bool isNonPointerStream()

Determines if the given template argument is a direct stream type, and that it is not a pointer. If true, then this implies that the caller "owns" the stream, and the stream should not be used outside of owner's scope.

isOutputStream
bool isOutputStream()

Determines if the given stream type is an output stream for writing data of the given type.

isPointerToStream
bool isPointerToStream()

Determines if the given template argument is a pointer to a stream.

isSeekableStream
bool isSeekableStream()

Determines if the given template argument is a seekable stream type, which is any stream, input or output, that defines a Optional!StreamError seekInStream(ulong offset) function for seeking to a particular position in a stream, specified by the offset in terms of elements.

isSomeInputStream
bool isSomeInputStream()

Determines if the given template argument is some form of input stream.

isSomeOutputStream
bool isSomeOutputStream()

Determines if the given template argument is some form of output stream.

isSomeStream
bool isSomeStream()

Determines if the given template argument is a stream of any kind; that is, it is at least implementing the functions required to be an input or output stream.

isSomeStream
bool isSomeStream()

Determines if the given stream type is an input or output stream for data of the given type.

Structs

ErrorInputStream
struct ErrorInputStream(T)

An input stream that always returns an error response.

ErrorOutputStream
struct ErrorOutputStream(T)

An output stream that always returns an error response.

NoOpInputStream
struct NoOpInputStream(T)

An input stream that always reads 0 elements.

NoOpOutputStream
struct NoOpOutputStream(T)

An output stream that always writes 0 elements.

StreamError
struct StreamError

An error that occurred during a stream operation, which includes a short message, as well as an integer code which is usually the last stream operation return code.

Templates

StreamType
template StreamType(S)

A template that evaluates to the type of a given input or output stream.

Meta