print

Examples

enum Flag
{
    no,
    yes,
}

import mir.appender: ScopedBuffer;
ScopedBuffer!char w;
w.print(Flag.yes);
assert(w.data == "yes", w.data);
import mir.appender: ScopedBuffer;
ScopedBuffer!char w;
assert(w.print(true).data == `true`, w.data);
w.reset;
assert(w.print(false).data == `false`, w.data);
import mir.appender: ScopedBuffer;
ScopedBuffer!char w;
w.print(["a": 1, "b": 2]);
assert(w.data == `["a": 1, "b": 2]` || w.data == `["b": 2, "a": 1]`, w.data);
import mir.appender: ScopedBuffer;
ScopedBuffer!char w;
string[2] array = ["a\ta", "b"];
assert(w.print(array[]).data == `["a\ta", "b"]`, w.data);
import mir.appender: ScopedBuffer;
ScopedBuffer!char w;
assert(w
    .print('\n')
    .print('\'')
    .print('a')
    .print('\xF4')
    .data == `'\n''\'''a''\xF4'`);
static struct A { scope const void toString(C, W)(scope ref W w) { w.put(C('a')); } }
static struct S { scope const void toString(W)(scope ref W w) { w.put("s"); } }
static struct D { scope const void toString(Dg)(scope Dg sink) { sink("d"); } }
static struct F { scope const const(char)[] toString()() return { return "f"; } }
static struct G { const(char)[] s = "g"; alias s this; }

import mir.appender: ScopedBuffer;
ScopedBuffer!char w;
assert(stringBuf() << A() << S() << D() << F() << G() << getData == "asdfg");
static class A { scope const void toString(C, W)(scope ref W w) { w.put(C('a')); } }
static class S { scope const void toString(W)(scope ref W w) { w.put("s"); } }
static class D { scope const void toString(Dg)(scope Dg sink) { sink("d"); } }
static class F { scope const const(char)[] toString()() return { return "f"; } }
static class G { const(char)[] s = "g"; alias s this; }

import mir.appender: ScopedBuffer;
ScopedBuffer!char w;
assert(stringBuf() << new A() << new S() << new D() << new F() << new G() << getData == "asdfg");

Meta