eh_file_read.dhover×131all
#!/usr/bin/env dub
/+ dub.sdl:
    name "eh_file_read"
    dependency "sparkles:event-horizon" path="../../../../.."
    buildType "checked" {
        buildOptions "optimize" "inline" "debugInfo"
    }
    platforms "linux"
+/
import 
(package) core
core
.
(module) core.lifetime
lifetime
:
(alias template) eh_file_read.move = core.lifetime.move(T)(ref T source, ref T target)

Moves source into target, via a destructive copy when necessary.

If T is a struct with a destructor or postblit defined, source is reset to its .init value after it is moved into target, otherwise it is left unchanged.

Preconditions

If source has internal pointers that point to itself and doesn't define opPostMove, it cannot be moved, and will trigger an assertion failure.

@paramsource Data to copy.@paramtarget Where to copy into. The destructor, if any, is invoked before the copy is performed.
move
;
import
(package) core
core
.
(package) core.sys
sys
.
(package) core.sys.posix
posix
.
(module) core.sys.posix.stdlib

D header file for POSIX.

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseBoost License 1.0.@authorsSean Kelly@standardsThe Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
stdlib
:
(alias) eh_file_read.mkdtemp = char* core.sys.posix.stdlib.mkdtemp(char*) nothrow @nogc
mkdtemp
;
import
(package) std
std
.
(module) std.file

Utilities for manipulating files and scanning directories. Functions in this module handle files as a unit, e.g., read or write one file at a time. For opening files and manipulating them via handles refer to module std.stdio.

Category Functions
General exists isDir isFile isSymlink rename thisExePath
Directories chdir dirEntries getcwd mkdir mkdirRecurse rmdir rmdirRecurse tempDir
Files append copy read readText remove slurp write
Symlinks symlink readLink
Attributes attrIsDir attrIsFile attrIsSymlink getAttributes getLinkAttributes getSize setAttributes
Timestamp getTimes getTimesWin setTimes timeLastModified timeLastAccessed timeStatusChanged
Other DirEntry FileException PreserveAttributes SpanMode getAvailableDiskSpace

Source

std/file.d

@copyrightCopyright The D Language Foundation 2007 - 2011.@seeThe official tutorial for an introduction to working with files in D, module std.stdio for opening files and manipulating them via handles, and module std.path for manipulating path strings.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Jonathan M Davis
file
:
(alias template) eh_file_read.remove = std.file.remove(R)(R name) if (isSomeFiniteCharInputRange!R && !isConvertibleToString!R)

Delete file name.

@paramname string or range of characters representing the file name@throwsFileException on error.
remove
,
(alias template) eh_file_read.rmdir = std.file.rmdir(R)(R pathname) if (isSomeFiniteCharInputRange!R && !isConvertibleToString!R)

Remove directory pathname.

@parampathname Range or string specifying the directory name@throwsFileException on error.
rmdir
,
(alias) eh_file_read.tempDir = string std.file.tempDir() @trusted

Returns the path to a directory for temporary files. On POSIX platforms, it searches through the following list of directories and returns the first one which is found to exist:

  1. The directory given by the TMPDIR environment variable.

  2. The directory given by the TEMP environment variable.

  3. The directory given by the TMP environment variable.

  4. /tmp/

  5. /var/tmp/

  6. /usr/tmp/

On all platforms, tempDir returns the current working directory on failure.

The return value of the function is cached, so the procedures described below will only be performed the first time the function is called. All subsequent runs will return the same string, regardless of whether environment variables and directory structures have changed in the meantime.

The POSIX tempDir algorithm is inspired by Python's tempfile.tempdir.

@returns

On Windows, this function returns the result of calling the Windows API function GetTempPath.

On POSIX platforms, it searches through the following list of directories and returns the first one which is found to exist:

  1. The directory given by the TMPDIR environment variable.

  2. The directory given by the TEMP environment variable.

  3. The directory given by the TMP environment variable.

  4. /tmp

  5. /var/tmp

  6. /usr/tmp

On all platforms, tempDir returns "." on failure, representing the current working directory.

tempDir
,
(alias template) eh_file_read.write = std.file.write(R)(R name, const void[] buffer) if ((isSomeFiniteCharInputRange!R || isSomeString!R) && !isConvertibleToString!R)

Write buffer to file name.

Creates the file if it does not already exist.

@paramname string or range of characters representing the file name@parambuffer data to be written to file@throwsFileException on error.@seetoFile
write
;
import
(package) std
std
.
(module) std.path

This module is used to manipulate path strings.

All functions, with the exception of expandTilde (and in some cases absolutePath and relativePath), are pure string manipulation functions; they don't depend on any state outside the program, nor do they perform any actual file system actions. This has the consequence that the module does not make any distinction between a path that points to a directory and a path that points to a file, and it does not know whether or not the object pointed to by the path actually exists in the file system. To differentiate between these cases, use isDir and exists.

Note that on Windows, both the backslash (\) and the slash (/) are in principle valid directory separators. This module treats them both on equal footing, but in cases where a new separator is added, a backslash will be used. Furthermore, the buildNormalizedPath function will replace all slashes with backslashes on that platform.

In general, the functions in this module assume that the input paths are well-formed. (That is, they should not contain invalid characters, they should follow the file system's path format, etc.) The result of calling a function on an ill-formed path is undefined. When there is a chance that a path or a file name is invalid (for instance, when it has been input by the user), it may sometimes be desirable to use the isValidFilename and isValidPath functions to check this.

Most functions do not perform any memory allocations, and if a string is returned, it is usually a slice of an input string. If a function allocates, this is explicitly mentioned in the documentation.

Category Functions
Normalization absolutePath asAbsolutePath asNormalizedPath asRelativePath buildNormalizedPath buildPath chainPath expandTilde
Partitioning baseName dirName dirSeparator driveName pathSeparator pathSplitter relativePath rootName stripDrive
Validation isAbsolute isDirSeparator isRooted isValidFilename isValidPath
Extension defaultExtension extension setExtension stripExtension withDefaultExtension withExtension
Other filenameCharCmp filenameCmp globMatch CaseSensitive

Source

std/path.d

@authorsLars Tandle Kyllingstad, Walter Bright, Grzegorz Adam Hankiewicz, Thomas Khne, Andrei Alexandrescu@copyrightCopyright (c) 2000-2014, the authors. All rights reserved.@licenseBoost License 1.0
path
:
(alias template) eh_file_read.buildPath = std.path.buildPath(Range)(scope Range segments) if (isInputRange!Range && !isInfinite!Range && isSomeString!(ElementType!Range))

Combines one or more path segments.

This function takes a set of path segments, given as an input range of string elements or as a set of string arguments, and concatenates them with each other. Directory separators are inserted between segments if necessary. If any of the path segments are absolute (as defined by isAbsolute), the preceding segments will be dropped.

On Windows, if one of the path segments are rooted, but not absolute (e.g. \foo), all preceding path segments down to the previous root will be dropped. (See below for an example.)

This function always allocates memory to hold the resulting path. The variadic overload is guaranteed to only perform a single allocation, as is the range version if paths is a forward range.

@paramsegments An input range of segments to assemble the path from.@returnsThe assembled path.
buildPath
;
import
(package) std
std
.
(module) std.stdio
Category Symbols
File handles _popen File isFileHandle openNetwork stderr stdin stdout
Reading chunks lines readf readfln readln
Writing toFile write writef writefln writeln
Misc KeepTerminator LockType StdioException

Standard I/O functions that extend core.stdc.stdio. core.stdc.stdio is publically imported when importing std.stdio.

There are three layers of I/O:

  1. The lowest layer is the operating system layer. The two main schemes are Windows and Posix.

  2. C's stdio.h which unifies the two operating system schemes.

  3. std.stdio, this module, unifies the various stdio.h implementations into a high level package for D programs.

Source

std/stdio.d

@copyrightCopyright The D Language Foundation 2007-.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Alex Rønne Petersen
stdio
:
(alias template) eh_file_read.writeln = std.stdio.writeln(T...)(T args)

Equivalent to write(args, '\n'). Calling writeln without arguments is valid and just prints a newline to the standard output.

Example

Reads stdin and writes it to stdout with an argument counter.

import std.stdio;

void main()
{
    string line;

    for (size_t count = 0; (line = readln) !is null; count++)
    {
         writeln("Input ", count, ": ", line);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
;
import
(package) sparkles
sparkles
.
(package) sparkles.base
base
.
(module) sparkles.base.buffer

A @nogc container with Small Buffer Optimization (SBO).

Provides an append-only buffer that stores small amounts of data inline (avoiding heap allocation) and automatically switches to heap storage when capacity is exceeded.

Primary use case: appending elements in a temporary scope where GC allocation is not desired.

buffer
:
(alias template) eh_file_read.UniqueBuffer = sparkles.base.buffer.UniqueBuffer(T, ulong N = max(size_t(1), (T[]).sizeof / T.sizeof))

Small-buffer optimization with a sole owner: inline while the elements fit, heap when they do not, and copying is disabled.

Disabling copies is what removes the reference count from the grow path — there is no second owner to consult. Hand a finished one to the shared world with toShared, which consumes it and transfers any heap block without reallocating.

UniqueBuffer
;
import
(package) sparkles
sparkles
.
(package) sparkles.base
base
.
(module) sparkles.base.vfs

The capability VFS: a file-system interface over directory handles.

A program is given open directory handles instead of path strings and names every file relative to one of them, so code holding a handle cannot reach anything outside that directory, even while another process renames entries or plants symbolic links inside it. Each handle carries rights checked at compile time, which can be narrowed but never widened.

Specified in docs/specs/base/vfs/SPEC.md.

vfs
:
(enum) sparkles.base.io.errors.ErrorKind

The portable classification of a failure.

ErrorKind
,
(struct) sparkles.base.vfs.types.OpenMode

An open mode (VFO4). It is a template argument of openFile, so the rights it needs are checked at compile time.

Examples

static assert(OpenMode.read.rights == Rights.read);
static assert(OpenMode.createNew.rights == (Rights.write | Rights.create));
static assert(!OpenMode.append.creates);
OpenMode
,
(enum) sparkles.base.vfs.types.Rights

The operations a handle permits (VFH4). Rights are part of a handle's type, so an operation whose right is absent does not compile (VFH6), and a derived handle can only have fewer (VFH5).

Rights
,
(alias) eh_file_read.ambientAuthority = sparkles.base.vfs.handles.AmbientAuthority sparkles.base.vfs.handles.ambientAuthority() pure nothrow @nogc @safe

The token openRoot requires (VFH7). Only ``ambientAuthority() makes one, so searching for that name finds every place that creates authority from a path.

ambientAuthority
,
(alias template) eh_file_read.openRoot = sparkles.base.vfs.handles.openRoot(Rights R, V)(V* vfs, scope const(char)[] path, AmbientAuthority authority, ResolvePolicy policy = ResolvePolicy.init, CreateDefault create = CreateDefault.shared_, bool requireKernel = false) if (isVfs!V)

Opens the directory path as a root with rights R (VFH7). The only operation that resolves a path from the process root or current directory, and the only one that follows symbolic links in the path it is given.

openRoot
;
import
(package) sparkles
sparkles
.
(module) sparkles.event_horizon

sparkles:event-horizon — the completion-first event loop with a native algebraic-effect layer. This package module re-exports the public surface (SPEC §16); import sparkles.event_horizon`` for the whole API, or a specific module for a narrower dependency.

event_horizon
;
void
void D main()
main
()
{ auto
(local variable) char[] template_
template_
= (
string std.path.buildPath!char(const(char)[][] paths...) pure nothrow @safe

Combines one or more path segments.

This function takes a set of path segments, given as an input range of string elements or as a set of string arguments, and concatenates them with each other. Directory separators are inserted between segments if necessary. If any of the path segments are absolute (as defined by isAbsolute), the preceding segments will be dropped.

On Windows, if one of the path segments are rooted, but not absolute (e.g. \foo), all preceding path segments down to the previous root will be dropped. (See below for an example.)

This function always allocates memory to hold the resulting path. The variadic overload is guaranteed to only perform a single allocation, as is the range version if paths is a forward range.

Examples

version (Posix)
{
    assert(buildPath("foo", "bar", "baz") == "foo/bar/baz");
    assert(buildPath("/foo/", "bar/baz")  == "/foo/bar/baz");
    assert(buildPath("/foo", "/bar")      == "/bar");
}

version (Windows)
{
    assert(buildPath("foo", "bar", "baz") == `foo\bar\baz`);
    assert(buildPath(`c:\foo`, `bar\baz`) == `c:\foo\bar\baz`);
    assert(buildPath("foo", `d:\bar`)     == `d:\bar`);
    assert(buildPath("foo", `\bar`)       == `\bar`);
    assert(buildPath(`c:\foo`, `\bar`)    == `c:\bar`);
}
@paramsegments An input range of segments to assemble the path from.@returnsThe assembled path.
buildPath
(
string std.file.tempDir() @trusted

Returns the path to a directory for temporary files. On POSIX platforms, it searches through the following list of directories and returns the first one which is found to exist:

  1. The directory given by the TMPDIR environment variable.

  2. The directory given by the TEMP environment variable.

  3. The directory given by the TMP environment variable.

  4. /tmp/

  5. /var/tmp/

  6. /usr/tmp/

On all platforms, tempDir returns the current working directory on failure.

The return value of the function is cached, so the procedures described below will only be performed the first time the function is called. All subsequent runs will return the same string, regardless of whether environment variables and directory structures have changed in the meantime.

The POSIX tempDir algorithm is inspired by Python's tempfile.tempdir.

Examples

import std.ascii : letters;
import std.conv : to;
import std.path : buildPath;
import std.random : randomSample;
import std.utf : byCodeUnit;

// random id with 20 letters
auto id = letters.byCodeUnit.randomSample(20).to!string;
auto myFile = tempDir.buildPath(id ~ "my_tmp_file");
scope(exit) myFile.remove;

myFile.write("hello");
assert(myFile.readText == "hello");
@returns

On Windows, this function returns the result of calling the Windows API function GetTempPath.

On POSIX platforms, it searches through the following list of directories and returns the first one which is found to exist:

  1. The directory given by the TMPDIR environment variable.

  2. The directory given by the TEMP environment variable.

  3. The directory given by the TMP environment variable.

  4. /tmp

  5. /var/tmp

  6. /usr/tmp

On all platforms, tempDir returns "." on failure, representing the current working directory.

tempDir
(), "eh-file-XXXXXX") ~ '\0').
char[] object.dup!char(const(char)[] a) pure nothrow @property @safe
dup
;
assert(
char* core.sys.posix.stdlib.mkdtemp(char*) nothrow @nogc
mkdtemp
(
(local variable) char[] template_
template_
.
(field) char* char[].ptr
ptr
) !is null);
const
(local variable) const(string) dir
dir
=
(local variable) char[] template_
template_
[0 .. $ - 1].
string object.idup!char(char[] a) pure nothrow @property @safe

Provide the .idup array property, which creates an immutable duplicate.

idup
;
scope (exit)
void std.file.rmdir!string(string pathname) @safe

Remove directory pathname.

@parampathname Range or string specifying the directory name@throwsFileException on error.
rmdir
(
(local variable) const(string) dir
dir
);
const
(local variable) const(string) path
path
=
string std.path.buildPath!char(const(char)[][] paths...) pure nothrow @safe

Combines one or more path segments.

This function takes a set of path segments, given as an input range of string elements or as a set of string arguments, and concatenates them with each other. Directory separators are inserted between segments if necessary. If any of the path segments are absolute (as defined by isAbsolute), the preceding segments will be dropped.

On Windows, if one of the path segments are rooted, but not absolute (e.g. \foo), all preceding path segments down to the previous root will be dropped. (See below for an example.)

This function always allocates memory to hold the resulting path. The variadic overload is guaranteed to only perform a single allocation, as is the range version if paths is a forward range.

Examples

version (Posix)
{
    assert(buildPath("foo", "bar", "baz") == "foo/bar/baz");
    assert(buildPath("/foo/", "bar/baz")  == "/foo/bar/baz");
    assert(buildPath("/foo", "/bar")      == "/bar");
}

version (Windows)
{
    assert(buildPath("foo", "bar", "baz") == `foo\bar\baz`);
    assert(buildPath(`c:\foo`, `bar\baz`) == `c:\foo\bar\baz`);
    assert(buildPath("foo", `d:\bar`)     == `d:\bar`);
    assert(buildPath("foo", `\bar`)       == `\bar`);
    assert(buildPath(`c:\foo`, `\bar`)    == `c:\bar`);
}
@paramsegments An input range of segments to assemble the path from.@returnsThe assembled path.
buildPath
(
(local variable) const(string) dir
dir
, "input.txt");
void std.file.write!string(string name, const(void[]) buffer) @safe

Write buffer to file name.

Creates the file if it does not already exist.

Examples

scope(exit)
{
    assert(exists(deleteme));
    remove(deleteme);
}

int[] a = [ 0, 1, 1, 2, 3, 5, 8 ];
write(deleteme, a); // deleteme is the name of a temporary file
const bytes = read(deleteme);
const fileInts = () @trusted { return cast(int[]) bytes; }();
assert(fileInts == a);
@paramname string or range of characters representing the file name@parambuffer data to be written to file@throwsFileException on error.@seetoFile
write
(
(local variable) const(string) path
path
, "hello from a file\n");
scope (exit)
void std.file.remove!string(string name) @safe

Delete file name.

@paramname string or range of characters representing the file name@throwsFileException on error.
remove
(
(local variable) const(string) path
path
);
(struct) sparkles.event_horizon.group.LoopGroup

A running loop group. Non-copyable; owns its worker scheduler(s).

LoopGroup
(local variable) sparkles.event_horizon.group.LoopGroup group
group
;
if (
(struct) sparkles.event_horizon.group.LoopGroup

A running loop group. Non-copyable; owns its worker scheduler(s).

LoopGroup
.
expected.Expected!(void, IoError, NoGcHook) sparkles.event_horizon.group.LoopGroup.start(out sparkles.event_horizon.group.LoopGroup group, in sparkles.event_horizon.group.LoopGroupConfig cfg = LoopGroupConfig(Topology.single, 0u, 256u, Flag.yes, Flag.yes, 256u, Flag.no))

Probes the kernel and starts the group. io_uring probe failure is a hard error (SPEC §3.4 — no epoll fallback).

start
(
(local variable) sparkles.event_horizon.group.LoopGroup group
group
).
bool expected.Expected!(void, sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).hasError!()() const pure nothrow @nogc @property @safe

Checks if Expected has error

hasError
)
assert(false, "no completion backend"); scope (exit)
(local variable) sparkles.event_horizon.group.LoopGroup group
group
.
void sparkles.event_horizon.group.LoopGroup.shutdown(core.time.Duration grace = dur(5L)) nothrow @safe

Tears down the group's workers.

shutdown
();
auto
(local variable) _error_ run
run
=
(local variable) sparkles.event_horizon.group.LoopGroup group
group
.
group.run
run
((ref
(alias) sparkles.event_horizon.group.RootScope = sparkles.event_horizon.scope_.Scope!(Sched, IoError)

The blessed live scope instantiation handed to the root fiber (SPEC §7.2, §11): a Scope over the ring-backed Sched executor with the IoError channel.

RootScope
(parameter) sparkles.event_horizon.scope_.Scope!(Sched, IoError) sc
sc
, ref
(alias) sparkles.event_horizon.live.Env = sparkles.event_horizon.capability.Ctx!(RingClock, RingVfs, RingNet, RingProc)

The default live capability row handed to the root fiber (SPEC §11). fs is on every backend: RingVfs needs no ring file operations (SPEC §10.5).

Env
(parameter) sparkles.event_horizon.capability.Ctx!(RingClock, RingVfs, RingNet, RingProc) env
env
) {
// Files are reached through a directory capability, and close // themselves; `read` borrows the file's descriptor. auto
(local variable) expected.Expected!(Dir!(RingVfs, Rights.readOnly), IoError, NoGcHook) root
root
=
expected.Expected!(Dir!(RingVfs, Rights.readOnly), IoError, NoGcHook) sparkles.base.vfs.handles.openRoot!(Rights.readOnly, sparkles.event_horizon.vfs.RingVfs)(sparkles.event_horizon.vfs.RingVfs* vfs, scope const(char)[] path, sparkles.base.vfs.handles.AmbientAuthority authority, sparkles.base.vfs.types.ResolvePolicy policy = ResolvePolicy(SymlinkPolicy.none, DotDotPolicy.reject, false), sparkles.base.vfs.types.CreateDefault create = CreateDefault.shared_, bool requireKernel = false) @safe

Opens the directory path as a root with rights R (VFH7). The only operation that resolves a path from the process root or current directory, and the only one that follows symbolic links in the path it is given.

openRoot
!(
(enum) sparkles.base.vfs.types.Rights

The operations a handle permits (VFH4). Rights are part of a handle's type, so an operation whose right is absent does not compile (VFH6), and a derived handle can only have fewer (VFH5).

Rights
.
(enum value) sparkles.base.vfs.types.Rights.readOnly = cast(ushort)15u

look up, list, stat and read

readOnly
)(&
(parameter) sparkles.event_horizon.capability.Ctx!(RingClock, RingVfs, RingNet, RingProc) env
env
.fs(),
(local variable) const(string) dir
dir
,
sparkles.base.vfs.handles.AmbientAuthority sparkles.base.vfs.handles.ambientAuthority() pure nothrow @nogc @safe

The token openRoot requires (VFH7). Only ``ambientAuthority() makes one, so searching for that name finds every place that creates authority from a path.

ambientAuthority
());
assert(
(local variable) expected.Expected!(Dir!(RingVfs, Rights.readOnly), IoError, NoGcHook) root
root
.
bool expected.Expected!(sparkles.base.vfs.handles.Dir!(RingVfs, Rights.readOnly), sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).hasValue!()() const pure nothrow @nogc @property @safe

Checks if Expected has value

hasValue
);
auto
(local variable) expected.Expected!(File!(RingVfs, cast(Rights)cast(ushort)12u), IoError, NoGcHook) missing
missing
=
(local variable) expected.Expected!(Dir!(RingVfs, Rights.readOnly), IoError, NoGcHook) root
root
.
inout(sparkles.base.vfs.handles.Dir!(RingVfs, Rights.readOnly)) expected.Expected!(sparkles.base.vfs.handles.Dir!(RingVfs, Rights.readOnly), sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).value!()() inout pure nothrow @nogc @property ref @safe

Returns the expected value if there is one.

With default Abort hook, it asserts when there is no value. It calls hook's onAccessEmptyValue otherwise.

It returns T.init when hook doesn't provide onAccessEmptyValue.

value
.openFile!(OpenMode.read)("missing");
assert(
(local variable) expected.Expected!(File!(RingVfs, cast(Rights)cast(ushort)12u), IoError, NoGcHook) missing
missing
.
bool expected.Expected!(sparkles.base.vfs.handles.File!(RingVfs, cast(Rights)cast(ushort)12u), sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).hasError!()() const pure nothrow @nogc @property @safe

Checks if Expected has error

hasError
&&
(local variable) expected.Expected!(File!(RingVfs, cast(Rights)cast(ushort)12u), IoError, NoGcHook) missing
missing
.
inout(sparkles.base.io.errors.IoError) expected.Expected!(sparkles.base.vfs.handles.File!(RingVfs, cast(Rights)cast(ushort)12u), sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).error() inout pure nothrow @nogc @property ref @safe

Returns the error value. May only be called when hasValue returns false.

If there is no error value, it calls hook's onAccessEmptyError.

It returns E.init when hook doesn't provide onAccessEmptyError.

error
.
(field) sparkles.base.io.errors.ErrorKind sparkles.base.io.errors.IoError.kind

what callers match on

kind
==
(enum) sparkles.base.io.errors.ErrorKind

The portable classification of a failure.

ErrorKind
.
(enum value) sparkles.base.io.errors.ErrorKind.notFound = 1

the named entry does not exist

notFound
);
auto
(local variable) expected.Expected!(File!(RingVfs, cast(Rights)cast(ushort)12u), IoError, NoGcHook) opened
opened
=
(local variable) expected.Expected!(Dir!(RingVfs, Rights.readOnly), IoError, NoGcHook) root
root
.
inout(sparkles.base.vfs.handles.Dir!(RingVfs, Rights.readOnly)) expected.Expected!(sparkles.base.vfs.handles.Dir!(RingVfs, Rights.readOnly), sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).value!()() inout pure nothrow @nogc @property ref @safe

Returns the expected value if there is one.

With default Abort hook, it asserts when there is no value. It calls hook's onAccessEmptyValue otherwise.

It returns T.init when hook doesn't provide onAccessEmptyValue.

value
.openFile!(OpenMode.read)("input.txt");
assert(
(local variable) expected.Expected!(File!(RingVfs, cast(Rights)cast(ushort)12u), IoError, NoGcHook) opened
opened
.
bool expected.Expected!(sparkles.base.vfs.handles.File!(RingVfs, cast(Rights)cast(ushort)12u), sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).hasValue!()() const pure nothrow @nogc @property @safe

Checks if Expected has value

hasValue
);
auto
(local variable) sparkles.base.vfs.handles.File!(RingVfs, cast(Rights)cast(ushort)12u) f
f
=
sparkles.base.vfs.handles.File!(RingVfs, cast(Rights)cast(ushort)12u) core.lifetime.move!(sparkles.base.vfs.handles.File!(RingVfs, cast(Rights)cast(ushort)12u))(ref return scope sparkles.base.vfs.handles.File!(RingVfs, cast(Rights)cast(ushort)12u) source) nothrow @safe

Examples

Non-copyable structs can still be moved:

struct S
{
    int a = 1;
    @disable this(this);
    ~this() pure nothrow @safe @nogc {}
}
S s1;
s1.a = 2;
S s2 = move(s1);
assert(s1.a == 1);
assert(s2.a == 2);
move
(
(local variable) expected.Expected!(File!(RingVfs, cast(Rights)cast(ushort)12u), IoError, NoGcHook) opened
opened
.
inout(sparkles.base.vfs.handles.File!(RingVfs, cast(Rights)cast(ushort)12u)) expected.Expected!(sparkles.base.vfs.handles.File!(RingVfs, cast(Rights)cast(ushort)12u), sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).value!()() inout pure nothrow @nogc @property ref @safe

Returns the expected value if there is one.

With default Abort hook, it asserts when there is no value. It calls hook's onAccessEmptyValue otherwise.

It returns T.init when hook doesn't provide onAccessEmptyValue.

value
);
(alias) sparkles.base.buffer.UniqueBuffer!(ubyte, 128LU) = sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u)

Small-buffer optimization with a sole owner: inline while the elements fit, heap when they do not, and copying is disabled.

Disabling copies is what removes the reference count from the grow path — there is no second owner to consult. Hand a finished one to the shared world with toShared, which consumes it and transfers any heap block without reallocating.

UniqueBuffer
!(ubyte, 128)
(local variable) sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u) buf
buf
;
(alias) object.string = string
string
(local variable) string contents
contents
;
for (;;) {
(local variable) sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u) buf
buf
.
void sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u).length(ulong newLength) pure nothrow @nogc @property @trusted

Sets the element count. Growing appends T.init-filled elements (one storage growth); shrinking drops elements from the back and keeps the storage, whichever it is (BUF13) — a buffer that has spilled to the heap stays there until clear or the destructor, so a shrink costs neither a copy back into the inline slots nor a free.

Output range interface: appends a single element.

length
= 128;
auto
(local variable) sparkles.event_horizon.io.BufResult!(Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u)) got
got
=
sparkles.event_horizon.io.BufResult!(Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u)) sparkles.event_horizon.io.read!(sparkles.base.vfs.handles.File!(RingVfs, cast(Rights)cast(ushort)12u), sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u))(ref sparkles.base.vfs.handles.File!(RingVfs, cast(Rights)cast(ushort)12u) h, sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u) buf, ulong offset = 18446744073709551615LU) nothrow @safe

Positioned read into the buffer's view (offset` == ulong.max` reads at the current file position — pipes and sockets require it). h`` is anything that lends a descriptor (isFdBorrowable): an OwnedFd, a BorrowedFd, or a capability VFS File whose backend has one.

read
(
(local variable) sparkles.base.vfs.handles.File!(RingVfs, cast(Rights)cast(ushort)12u) f
f
,
sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u) core.lifetime.move!(sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u))(ref return scope sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u) source) pure nothrow @nogc @safe

Examples

Non-copyable structs can still be moved:

struct S
{
    int a = 1;
    @disable this(this);
    ~this() pure nothrow @safe @nogc {}
}
S s1;
s1.a = 2;
S s2 = move(s1);
assert(s1.a == 1);
assert(s2.a == 2);
move
(
(local variable) sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u) buf
buf
),
(local variable) string contents
contents
.
(field) ulong string.length
length
);
(local variable) sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u) buf
buf
=
sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u) sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u).opAssign(scope sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u) rhs) pure nothrow @nogc ref return scope @trusted

Move assignment from an rvalue: release current storage, then steal rhs's storage (no refcount change — ownership transfers). rhs is neutralized so its destructor frees nothing.

move
(
sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u) sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u).opAssign(scope sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u) rhs) pure nothrow @nogc ref return scope @trusted

Move assignment from an rvalue: release current storage, then steal rhs's storage (no refcount change — ownership transfers). rhs is neutralized so its destructor frees nothing.

got
.
(field) sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u) sparkles.event_horizon.io.BufResult!(sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u)).buf

ownership returned — the kernel is done with it

buf
);
assert(
(local variable) sparkles.event_horizon.io.BufResult!(Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u)) got
got
.
(field) expected.Expected!(uint, IoError, NoGcHook) sparkles.event_horizon.io.BufResult!(sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u)).res

bytes transferred, or the error

res
.
bool expected.Expected!(uint, sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).hasValue!()() const pure nothrow @nogc @property @safe

Checks if Expected has value

hasValue
);
if (
(local variable) sparkles.event_horizon.io.BufResult!(Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u)) got
got
.
(field) expected.Expected!(uint, IoError, NoGcHook) sparkles.event_horizon.io.BufResult!(sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u)).res

bytes transferred, or the error

res
.
inout(uint) expected.Expected!(uint, sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).value!()() inout pure nothrow @nogc @property ref @safe

Returns the expected value if there is one.

With default Abort hook, it asserts when there is no value. It calls hook's onAccessEmptyValue otherwise.

It returns T.init when hook doesn't provide onAccessEmptyValue.

value
== 0)
break;
(local variable) string contents
contents
~= cast(const(char)[])
(local variable) sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u) buf
buf
[][0 ..
(local variable) sparkles.event_horizon.io.BufResult!(Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u)) got
got
.
(field) expected.Expected!(uint, IoError, NoGcHook) sparkles.event_horizon.io.BufResult!(sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u)).res

bytes transferred, or the error

res
.
inout(uint) expected.Expected!(uint, sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).value!()() inout pure nothrow @nogc @property ref @safe

Returns the expected value if there is one.

With default Abort hook, it asserts when there is no value. It calls hook's onAccessEmptyValue otherwise.

It returns T.init when hook doesn't provide onAccessEmptyValue.

value
];
} assert(
(local variable) string contents
contents
== "hello from a file\n");
void std.stdio.writeln!(string, ulong, string, string)(string __param_0, ulong __param_1, string __param_2, string __param_3) @safe

Equivalent to write(args, '\n'). Calling writeln without arguments is valid and just prints a newline to the standard output.

Example

Reads stdin and writes it to stdout with an argument counter.

import std.stdio;

void main()
{
    string line;

    for (size_t count = 0; (line = readln) !is null; count++)
    {
         writeln("Input ", count, ": ", line);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
("read ",
(local variable) string contents
contents
.
(field) ulong string.length
length
, " bytes: ",
(local variable) string contents
contents
);
return 0; }); assert(run.
(field) _error_ run.hasValue
hasValue
);
}