#!/usr/bin/env dub
/+ dub.sdl:
name "vibe_exec"
dependency "vibe-core" version="2.14.0"
buildType "checked" {
buildOptions "optimize" "inline" "debugInfo"
}
platforms "linux"
+/
import (package) stdstd.(module) std.arrayFunctions and types that manipulate built-in arrays and associative arrays.
This module provides all kinds of functions to create, manipulate or convert arrays:
Function Name Description
| array |
Returns a copy of the input in a newly allocated dynamic array.
|
| appender |
Returns a new Appender or RefAppender initialized with a given array.
|
| assocArray |
Returns a newly allocated associative array from a range/ranges of keys and values.
|
| byPair |
Construct a range iterating over an associative array by key/value tuples.
|
| insertInPlace |
Inserts into an existing array at a given position.
|
| join |
Concatenates a range of ranges into one array.
|
| minimallyInitializedArray |
Returns a new array of type T.
|
| replace |
Returns a new array with all occurrences of a certain subrange replaced.
|
| replaceFirst |
Returns a new array with the first occurrence of a certain subrange replaced.
|
| replaceInPlace |
Replaces all occurrences of a certain subrange and puts the result into a given array.
|
| replaceInto |
Replaces all occurrences of a certain subrange and puts the result into an output range.
|
| replaceLast |
Returns a new array with the last occurrence of a certain subrange replaced.
|
| replaceSlice |
Returns a new array with a given slice replaced.
|
| replicate |
Creates a new array out of several copies of an input array or range.
|
| sameHead |
Checks if the initial segments of two arrays refer to the same
place in memory.
|
| sameTail |
Checks if the final segments of two arrays refer to the same place
in memory.
|
| split |
Eagerly split a range or string into an array.
|
| staticArray |
Creates a new static array from given data.
|
| uninitializedArray |
Returns a new array of type T without initializing its elements.
|
Source
std/array.d
array : (alias template) vibe_exec.appender = std.array.appender(A)() if (isDynamicArray!A)Convenience function that returns an Appender instance,
optionally initialized with array.
appender;
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) vibe_exec.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) vibevibe.(package) vibe.corecore.(module) vibe.core.coreThis module contains the core functionality of the vibe.d framework.
core : (alias template) vibe_exec.runTask = vibe.core.core.runTask(ARGS...)(void delegate(ARGS) nothrow @safe task, auto ref ARGS args)Runs a new asynchronous task.
task will be called synchronously from within the vibeRunTask call. It will
continue to run until vibeYield() or any of the I/O or wait functions is
called.
Note that the maximum size of all args must not exceed maxTaskParameterSize.
runTask;
import (package) vibevibe.(package) vibe.corecore.(module) vibe.core.processFunctions and structures for dealing with subprocesses and pipes.
This module is modeled after std.process, but provides a fiber-aware
alternative to it. All blocking operations will yield the calling fiber
instead of blocking it.
process : (alias) vibe_exec.pipeProcess = vibe.core.process.ProcessPipes vibe.core.process.pipeProcess(scope string[] args, std.process.Redirect redirect = Redirect.all, const(string[string]) env = cast(const(string[string]))null, vibe.core.process.Config config = Config(Flags.none, null, null), scope vibe.core.path.GenericPath!(PosixPathFormat) workDir = GenericPath(null)) @trustedEquivalent to std.process.pipeProcess``.
pipeProcess, (enum) std.process.RedirectFlags that can be passed to pipeProcess and pipeShell
to specify which of the child process' standard streams are redirected.
Use bitwise OR to combine flags.
Redirect;
import (package) vibevibe.(package) vibe.corecore.(module) vibe.core.streamGeneric stream interface used by several stream-like classes.
This module defines the basic (buffered) stream primitives. For concrete stream types, take a
look at the vibe.stream`` package. The vibe.stream.operations module contains additional
high-level operations on streams, such as reading streams by line or as a whole.
Note that starting with vibe-core 1.0.0, streams can be of either struct or class type.
Any APIs that take streams as a parameter should use a template type parameter that is tested
using the appropriate trait (e.g. isInputStream) instead of assuming the specific interface
type (e.g. InputStream).
stream : (enum) eventcore.driver.IOModeIOMode;
void void D main()main()
{
auto (local variable) vibe.core.process.ProcessPipes pipespipes = vibe.core.process.ProcessPipes vibe.core.process.pipeProcess(scope string[] args, std.process.Redirect redirect = Redirect.all, const(string[string]) env = cast(const(string[string]))null, vibe.core.process.Config config = Config(Flags.none, null, null), scope vibe.core.path.GenericPath!(PosixPathFormat) workDir = GenericPath(null)) @trustedEquivalent to std.process.pipeProcess``.
pipeProcess(["sh", "-c", "echo out; echo err >&2; exit 3"], (enum) std.process.RedirectFlags that can be passed to pipeProcess and pipeShell
to specify which of the child process' standard streams are redirected.
Use bitwise OR to combine flags.
Redirect.(enum value) std.process.Redirect.all = 7Redirect all three streams. This is equivalent to
Redirect.stdin | Redirect.stdout | Redirect.stderr.
all);
auto (local variable) std.array.Appender!string outBufoutBuf = std.array.Appender!string std.array.appender!string() pure nothrow @safeConvenience function that returns an Appender instance,
optionally initialized with array.
appender!(alias) object.string = stringstring;
auto (local variable) std.array.Appender!string errBuferrBuf = std.array.Appender!string std.array.appender!string() pure nothrow @safeConvenience function that returns an Appender instance,
optionally initialized with array.
appender!(alias) object.string = stringstring;
// Must drain stdout and stderr concurrently to prevent pipe buffer deadlocks
auto (local variable) vibe.core.task.Task tOuttOut = vibe.core.task.Task vibe.core.core.runTask!()(void delegate() nothrow @safe task) nothrow @safeRuns a new asynchronous task.
task will be called synchronously from within the vibeRunTask call. It will
continue to run until vibeYield() or any of the I/O or wait functions is
called.
Note that the maximum size of all args must not exceed maxTaskParameterSize.
runTask(() nothrow {
try {
ubyte[128] (local variable) ubyte[128] bufbuf;
while (!(local variable) vibe.core.process.ProcessPipes pipespipes.(field) vibe.core.process.PipeInputStream vibe.core.process.ProcessPipes.stdoutstdout.bool vibe.core.process.PipeInputStream.empty() @property @safeempty) {
const (local variable) const(ulong) nn = (local variable) vibe.core.process.ProcessPipes pipespipes.(field) vibe.core.process.PipeInputStream vibe.core.process.ProcessPipes.stdoutstdout.ulong vibe.core.process.PipeInputStream.read(scope ubyte[] dst, eventcore.driver.IOMode mode) @saferead((local variable) ubyte[128] bufbuf[], (enum) eventcore.driver.IOModeIOMode.(enum value) eventcore.driver.IOMode.once = 1Process as much as possible with a single call
once);
(local variable) std.array.Appender!string outBufoutBuf.void std.array.Appender!string.put!(const(char)[])(const(char)[] items) pure nothrow @safeAppends an entire range to the managed array. Performs encoding for
char elements if A is a differently typed char array.
put(cast(const(char)[]) (local variable) ubyte[128] bufbuf[0 .. (local variable) const(ulong) nn]);
}
} catch ((class) object.ExceptionThe base class of all errors that are safe to catch and handle.
In principle, only thrown objects derived from this class are safe to catch
inside a catch block. Thrown objects not derived from Exception
represent runtime errors that should not be caught, as certain runtime
guarantees may not hold, making it unsafe to continue program execution.
Examples
bool gotCaught;
try
{
throw new Exception("msg");
}
catch (Exception e)
{
gotCaught = true;
assert(e.msg == "msg");
}
assert(gotCaught);
Exception (local variable) object.Exception errorerror) { assert(false, (local variable) object.Exception errorerror.(field) string object.Throwable.msgA message describing the error.
msg); }
});
auto (local variable) vibe.core.task.Task tErrtErr = vibe.core.task.Task vibe.core.core.runTask!()(void delegate() nothrow @safe task) nothrow @safeRuns a new asynchronous task.
task will be called synchronously from within the vibeRunTask call. It will
continue to run until vibeYield() or any of the I/O or wait functions is
called.
Note that the maximum size of all args must not exceed maxTaskParameterSize.
runTask(() nothrow {
try {
ubyte[128] (local variable) ubyte[128] bufbuf;
while (!(local variable) vibe.core.process.ProcessPipes pipespipes.(field) vibe.core.process.PipeInputStream vibe.core.process.ProcessPipes.stderrstderr.bool vibe.core.process.PipeInputStream.empty() @property @safeempty) {
const (local variable) const(ulong) nn = (local variable) vibe.core.process.ProcessPipes pipespipes.(field) vibe.core.process.PipeInputStream vibe.core.process.ProcessPipes.stderrstderr.ulong vibe.core.process.PipeInputStream.read(scope ubyte[] dst, eventcore.driver.IOMode mode) @saferead((local variable) ubyte[128] bufbuf[], (enum) eventcore.driver.IOModeIOMode.(enum value) eventcore.driver.IOMode.once = 1Process as much as possible with a single call
once);
(local variable) std.array.Appender!string errBuferrBuf.void std.array.Appender!string.put!(const(char)[])(const(char)[] items) pure nothrow @safeAppends an entire range to the managed array. Performs encoding for
char elements if A is a differently typed char array.
put(cast(const(char)[]) (local variable) ubyte[128] bufbuf[0 .. (local variable) const(ulong) nn]);
}
} catch ((class) object.ExceptionThe base class of all errors that are safe to catch and handle.
In principle, only thrown objects derived from this class are safe to catch
inside a catch block. Thrown objects not derived from Exception
represent runtime errors that should not be caught, as certain runtime
guarantees may not hold, making it unsafe to continue program execution.
Examples
bool gotCaught;
try
{
throw new Exception("msg");
}
catch (Exception e)
{
gotCaught = true;
assert(e.msg == "msg");
}
assert(gotCaught);
Exception (local variable) object.Exception errorerror) { assert(false, (local variable) object.Exception errorerror.(field) string object.Throwable.msgA message describing the error.
msg); }
});
const (local variable) const(int) statusstatus = (local variable) vibe.core.process.ProcessPipes pipespipes.(field) vibe.core.process.Process vibe.core.process.ProcessPipes.processprocess.int vibe.core.process.Process.wait() @safeWait for the process to exit, allowing other fibers to continue in the
meantime.
wait();
(local variable) vibe.core.task.Task tOuttOut.void vibe.core.task.Task.join() @trustedjoin();
(local variable) vibe.core.task.Task tErrtErr.void vibe.core.task.Task.join() @trustedjoin();
assert((local variable) const(int) statusstatus == 3);
assert((local variable) std.array.Appender!string outBufoutBuf.string std.array.Appender!string.data() inout pure nothrow @nogc @property @safeUse opSlice() from now on.
data == "out\n");
assert((local variable) std.array.Appender!string errBuferrBuf.string std.array.Appender!string.data() inout pure nothrow @nogc @property @safeUse opSlice() from now on.
data == "err\n");
void std.stdio.writeln!(string, string)(string __param_0, string __param_1) @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("stdout: ", (local variable) std.array.Appender!string outBufoutBuf.string std.array.Appender!string.data() inout pure nothrow @nogc @property @safeUse opSlice() from now on.
data);
void std.stdio.writeln!(string, string)(string __param_0, string __param_1) @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("stderr: ", (local variable) std.array.Appender!string errBuferrBuf.string std.array.Appender!string.data() inout pure nothrow @nogc @property @safeUse opSlice() from now on.
data);
void std.stdio.writeln!(string, const(int))(string __param_0, const(int) __param_1) @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("exit code: ", (local variable) const(int) statusstatus);
}