@@ -18,8 +18,9 @@ struct WitList(T) {
1818 T* ptr;
1919 size_t length;
2020
21- this (T[] slice) @trusted {
22- this = slice;
21+ this (inout T[] slice) inout @trusted {
22+ ptr = slice.ptr;
23+ length = slice.length;
2324 }
2425
2526 void opAssign (T[] slice) @trusted {
@@ -35,8 +36,7 @@ struct WitList(T) {
3536 bool opEquals (in T[] other) const => this [] == other;
3637 size_t toHash () const => this [].hashOf;
3738}
38- auto witList (T : U[], U)(T slice) => WitList! U(slice);
39-
39+ auto witList (T : U[], U)(inout T slice) => inout WitList! U(slice);
4040
4141// WIT ABI for string matches List,
4242// except list<char> in WIT is actually List!(dchar)
@@ -140,17 +140,17 @@ private:
140140 bool _present = false ;
141141 T _value;
142142
143- this (bool present, T value = T.init) @safe @nogc nothrow {
143+ this (bool present, inout T value) inout @safe @nogc nothrow {
144144 _present = present;
145145 _value = value;
146146 }
147147public :
148- static Option some (T value) @safe @nogc nothrow {
149- return Option (true , value);
148+ static inout ( Option) some (inout T value) @safe @nogc nothrow {
149+ return inout Option(true , value);
150150 }
151151
152152 static Option none () @safe @nogc nothrow {
153- return Option (false );
153+ return Option (false , T.init );
154154 }
155155
156156 bool isSome () const @safe @nogc nothrow => _present;
@@ -168,12 +168,12 @@ public:
168168 { return _present ? _value : fallback(); }
169169}
170170
171- auto some (T)(T value) @safe @nogc nothrow {
171+ auto some (T)(inout T value) @safe @nogc nothrow {
172172 return Option! T.some(value);
173173}
174174
175- auto none (T)(T value ) @safe @nogc nothrow {
176- return Option! T.some(value) ;
175+ auto none (T)() @safe @nogc nothrow {
176+ return Option! T.none ;
177177}
178178
179179// / Based on Rust's Result
@@ -192,7 +192,7 @@ private:
192192 }
193193 Storage _storage;
194194
195- this (bool hasError, Storage storage) @safe @nogc nothrow {
195+ this (bool hasError, inout ( Storage) storage) inout @safe @nogc nothrow {
196196 _hasError = hasError;
197197 _storage = storage;
198198 }
@@ -201,22 +201,22 @@ public:
201201 static if (is (T == void )) {
202202 static Result ok () @safe @nogc nothrow => Result(false , Storage.init);
203203 } else {
204- static Result ok (T value) @trusted @nogc nothrow {
204+ static Result ok (inout (T) value) @trusted @nogc nothrow {
205205 Storage newStorage = Storage.init;
206- newStorage.value = value;
206+ newStorage.value = cast (T) value;
207207
208- return Result (false , newStorage);
208+ return Result (false , cast ( inout Storage) newStorage);
209209 }
210210 }
211211
212212 static if (is (E == void )) {
213213 static Result err () @safe @nogc nothrow => Result(true , Storage.init);
214214 } else {
215- static Result err (E error) @trusted @nogc nothrow {
215+ static inout ( Result) err (inout (E) error) @trusted @nogc nothrow {
216216 Storage newStorage = Storage.init;
217- newStorage.error = error;
217+ newStorage.error = cast (E) error;
218218
219- return Result (true , newStorage);
219+ return inout Result(true , cast ( inout Storage) newStorage);
220220 }
221221 }
222222
@@ -320,6 +320,20 @@ T witClone(T : Tuple!U, U...)(in T val) {
320320 return clone;
321321}
322322
323+
324+ void witFree (T : U[L], U, size_t L)(scope ref T val) {
325+ foreach (ref e; val) {
326+ e.witFree;
327+ }
328+ }
329+ T witClone (T : U[L], U, size_t L)(in T val) {
330+ T clone;
331+ foreach (i, ref e; clone) {
332+ e = val[i].witClone;
333+ }
334+ return clone;
335+ }
336+
323337package (wit):
324338
325339extern (C ) {
0 commit comments