From c30b17f3f413842a634e4df7ca3f9460bb2962ef Mon Sep 17 00:00:00 2001 From: drug007 Date: Tue, 12 May 2020 12:17:41 +0300 Subject: [PATCH] `TaggedUnion.toString` supports @safe Currently used `void delegate(const(char)[])` is not @safe by definition. In contrast `toString(W)` is able to deduce @safe-ty --- source/taggedalgebraic/taggedunion.d | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/source/taggedalgebraic/taggedunion.d b/source/taggedalgebraic/taggedunion.d index 9ce35fa..f3db2c7 100644 --- a/source/taggedalgebraic/taggedunion.d +++ b/source/taggedalgebraic/taggedunion.d @@ -325,11 +325,6 @@ align(commonAlignment!(UnionKindTypes!(UnionFieldEnum!U))) struct TaggedUnion if (isOutputRange!(W, char)) { import std.range.primitives : put; - toString(s => put(w, s)); - } - /// ditto - void toString(scope void delegate(const(char)[]) sink) - const { import std.conv : text; import std.format : FormatSpec, formatValue; @@ -337,24 +332,23 @@ align(commonAlignment!(UnionKindTypes!(UnionFieldEnum!U))) struct TaggedUnion foreach (i, v; EnumMembers!Kind) { case v: enum vstr = text(v); - static if (isUnitType!(FieldTypes[i])) sink(vstr); + static if (isUnitType!(FieldTypes[i])) put(w, vstr); else { // NOTE: using formatValue instead of formattedWrite // because formattedWrite does not work for // non-copyable types enum prefix = "(" ~ vstr ~ ": "; enum suffix = ")"; - sink(prefix); + put(w, prefix); FormatSpec!char spec; - sink.formatValue(value!v, spec); - sink(suffix); + formatValue(w, value!v, spec); + put(w, suffix); } break; } } } - package @trusted @property ref inout(T) trustedGet(T)() inout { return *cast(inout(T)*)m_data.ptr; } } }