diff --git a/vlib/builtin/byte_test.v b/vlib/builtin/byte_test.v new file mode 100644 index 0000000000..27357a44de --- /dev/null +++ b/vlib/builtin/byte_test.v @@ -0,0 +1,8 @@ +fn test_clone() { + a := [byte(0), 1, 2] + b := a.clone() + assert b.len == 3 + assert b[0] == 0 + assert b[1] == 1 + assert b[2] == 2 +} diff --git a/vlib/builtin/int.v b/vlib/builtin/int.v index 117737781a..c1ba5b617d 100644 --- a/vlib/builtin/int.v +++ b/vlib/builtin/int.v @@ -177,3 +177,11 @@ pub fn (c byte) str() string { return str } +pub fn (b []byte) clone() []byte { + mut res := [byte(0); b.len] + for i := 0; i < b.len; i++ { + res[i] = b[i] + } + return res +} +