#!/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) corecore.(module) core.lifetimelifetime : (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.
move;
import (package) corecore.(package) core.syssys.(package) core.sys.posixposix.(module) core.sys.posix.stdlibD header file for POSIX.
stdlib : (alias) eh_file_read.mkdtemp = char* core.sys.posix.stdlib.mkdtemp(char*) nothrow @nogcmkdtemp;
import (package) stdstd.(module) std.fileUtilities 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
file : (alias template) eh_file_read.remove = std.file.remove(R)(R name) if (isSomeFiniteCharInputRange!R && !isConvertibleToString!R)Delete file name.
remove, (alias template) eh_file_read.rmdir = std.file.rmdir(R)(R pathname) if (isSomeFiniteCharInputRange!R && !isConvertibleToString!R)Remove directory pathname.
rmdir, (alias) eh_file_read.tempDir = string std.file.tempDir() @trustedReturns 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:
The directory given by the TMPDIR environment variable.
The directory given by the TEMP environment variable.
The directory given by the TMP environment variable.
/tmp/
/var/tmp/
/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.
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.
write;
import (package) stdstd.(module) std.pathThis 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
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.
buildPath;
import (package) stdstd.(module) std.stdioCategory 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:
The lowest layer is the operating system layer. The two main schemes are Windows and Posix.
C's stdio.h which unifies the two operating system schemes.
std.stdio, this module, unifies the various stdio.h implementations into
a high level package for D programs.
Source
std/stdio.d
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);
}
}
writeln;
import (package) sparklessparkles.(package) sparkles.basebase.(module) sparkles.base.bufferA @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) sparklessparkles.(package) sparkles.basebase.(module) sparkles.base.vfsThe 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.ErrorKindThe portable classification of a failure.
ErrorKind, (struct) sparkles.base.vfs.types.OpenModeAn 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.RightsThe 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 @safeThe 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) sparklessparkles.(module) sparkles.event_horizonsparkles: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 @safeCombines 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`);
}
buildPath(string std.file.tempDir() @trustedReturns 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:
The directory given by the TMPDIR environment variable.
The directory given by the TEMP environment variable.
The directory given by the TMP environment variable.
/tmp/
/var/tmp/
/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");
tempDir(), "eh-file-XXXXXX") ~ '\0').char[] object.dup!char(const(char)[] a) pure nothrow @property @safedup;
assert(char* core.sys.posix.stdlib.mkdtemp(char*) nothrow @nogcmkdtemp((local variable) char[] template_template_.(field) char* char[].ptrptr) !is null);
const (local variable) const(string) dirdir = (local variable) char[] template_template_[0 .. $ - 1].string object.idup!char(char[] a) pure nothrow @property @safeProvide the .idup array property, which creates an immutable duplicate.
idup;
scope (exit) void std.file.rmdir!string(string pathname) @safeRemove directory pathname.
rmdir((local variable) const(string) dirdir);
const (local variable) const(string) pathpath = string std.path.buildPath!char(const(char)[][] paths...) pure nothrow @safeCombines 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`);
}
buildPath((local variable) const(string) dirdir, "input.txt");
void std.file.write!string(string name, const(void[]) buffer) @safeWrite 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);
write((local variable) const(string) pathpath, "hello from a file\n");
scope (exit) void std.file.remove!string(string name) @safeDelete file name.
remove((local variable) const(string) pathpath);
(struct) sparkles.event_horizon.group.LoopGroupA running loop group. Non-copyable; owns its worker scheduler(s).
LoopGroup (local variable) sparkles.event_horizon.group.LoopGroup groupgroup;
if ((struct) sparkles.event_horizon.group.LoopGroupA 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 groupgroup).bool expected.Expected!(void, sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).hasError!()() const pure nothrow @nogc @property @safeChecks if Expected has error
hasError)
assert(false, "no completion backend");
scope (exit) (local variable) sparkles.event_horizon.group.LoopGroup groupgroup.void sparkles.event_horizon.group.LoopGroup.shutdown(core.time.Duration grace = dur(5L)) nothrow @safeTears down the group's workers.
shutdown();
auto (local variable) _error_ runrun = (local variable) sparkles.event_horizon.group.LoopGroup groupgroup.group.runrun((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) scsc, 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) envenv) {
// 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) rootroot = 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) @safeOpens 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.RightsThe 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)15ulook up, list, stat and read
readOnly)(&(parameter) sparkles.event_horizon.capability.Ctx!(RingClock, RingVfs, RingNet, RingProc) envenv.fs(), (local variable) const(string) dirdir, sparkles.base.vfs.handles.AmbientAuthority sparkles.base.vfs.handles.ambientAuthority() pure nothrow @nogc @safeThe 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) rootroot.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 @safeChecks if Expected has value
hasValue);
auto (local variable) expected.Expected!(File!(RingVfs, cast(Rights)cast(ushort)12u), IoError, NoGcHook) missingmissing = (local variable) expected.Expected!(Dir!(RingVfs, Rights.readOnly), IoError, NoGcHook) rootroot.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 @safeReturns 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) missingmissing.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 @safeChecks if Expected has error
hasError && (local variable) expected.Expected!(File!(RingVfs, cast(Rights)cast(ushort)12u), IoError, NoGcHook) missingmissing.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 @safeReturns 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.kindwhat callers match on
kind == (enum) sparkles.base.io.errors.ErrorKindThe portable classification of a failure.
ErrorKind.(enum value) sparkles.base.io.errors.ErrorKind.notFound = 1the named entry does not exist
notFound);
auto (local variable) expected.Expected!(File!(RingVfs, cast(Rights)cast(ushort)12u), IoError, NoGcHook) openedopened = (local variable) expected.Expected!(Dir!(RingVfs, Rights.readOnly), IoError, NoGcHook) rootroot.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 @safeReturns 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) openedopened.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 @safeChecks if Expected has value
hasValue);
auto (local variable) sparkles.base.vfs.handles.File!(RingVfs, cast(Rights)cast(ushort)12u) ff = 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 @safeExamples
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) openedopened.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 @safeReturns 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) bufbuf;
(alias) object.string = stringstring (local variable) string contentscontents;
for (;;)
{
(local variable) sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u) bufbuf.void sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u).length(ulong newLength) pure nothrow @nogc @property @trustedSets 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)) gotgot = 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 @safePositioned 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) ff, 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 @safeExamples
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) bufbuf), (local variable) string contentscontents.(field) ulong string.lengthlength);
(local variable) sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u) bufbuf = 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 @trustedMove 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 @trustedMove 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)).bufownership returned — the kernel is done with it
buf);
assert((local variable) sparkles.event_horizon.io.BufResult!(Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u)) gotgot.(field) expected.Expected!(uint, IoError, NoGcHook) sparkles.event_horizon.io.BufResult!(sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u)).resbytes 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 @safeChecks if Expected has value
hasValue);
if ((local variable) sparkles.event_horizon.io.BufResult!(Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u)) gotgot.(field) expected.Expected!(uint, IoError, NoGcHook) sparkles.event_horizon.io.BufResult!(sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u)).resbytes 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 @safeReturns 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 contentscontents ~= cast(const(char)[]) (local variable) sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u) bufbuf[][0 .. (local variable) sparkles.event_horizon.io.BufResult!(Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u)) gotgot.(field) expected.Expected!(uint, IoError, NoGcHook) sparkles.event_horizon.io.BufResult!(sparkles.base.buffer.Buffer!(ubyte, 128LU, cast(Storage)cast(ubyte)7u)).resbytes 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 @safeReturns 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 contentscontents == "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) @safeEquivalent 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);
}
}
writeln("read ", (local variable) string contentscontents.(field) ulong string.lengthlength, " bytes: ", (local variable) string contentscontents);
return 0;
});
assert(run.(field) _error_ run.hasValuehasValue);
}