File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1143,6 +1143,11 @@ pub const Payload = union(enum) {
11431143 try self .map .put (key , val );
11441144 }
11451145
1146+ /// deep clone a Payload, allocating owned copies for dynamic data
1147+ pub fn deepClone (self : Payload , allocator : Allocator ) ! Payload {
1148+ return clonePayload (self , allocator );
1149+ }
1150+
11461151 /// get a NIL payload
11471152 pub inline fn nilToPayload () Payload {
11481153 return Payload {
Original file line number Diff line number Diff line change @@ -1184,6 +1184,11 @@ test "payload utility methods" {
11841184 try expect (ext_payload .ext .type == 1 );
11851185 try expect (u8eql ("extdata" , ext_payload .ext .data ));
11861186
1187+ const cloned_str_payload = try str_payload .deepClone (allocator );
1188+ defer cloned_str_payload .free (allocator );
1189+ try expect (u8eql ("test" , cloned_str_payload .str .value ()));
1190+ try expect (@ptrToInt (str_payload .str .value ().ptr ) != @ptrToInt (cloned_str_payload .str .value ().ptr ));
1191+
11871192 const arr_payload = try Payload .arrPayload (3 , allocator );
11881193 defer arr_payload .free (allocator );
11891194 try expect ((try arr_payload .getArrLen ()) == 3 );
You can’t perform that action at this time.
0 commit comments