diff --git a/builtin/builtin.mbti b/builtin/builtin.mbti index 0926ef1e9..8cd2a0610 100644 --- a/builtin/builtin.mbti +++ b/builtin/builtin.mbti @@ -535,6 +535,7 @@ fn[A] FixedArray::unsafe_blit(Self[A], Int, Self[A], Int, Int) -> Unit fn[T] FixedArray::unsafe_get(Self[T], Int) -> T fn[T] FixedArray::unsafe_set(Self[T], Int, T) -> Unit +#deprecated fn Bytes::copy(Bytes) -> Bytes fn Bytes::length(Bytes) -> Int fn Bytes::make(Int, Byte) -> Bytes diff --git a/builtin/bytes.mbt b/builtin/bytes.mbt index 20c73538d..dccb660af 100644 --- a/builtin/bytes.mbt +++ b/builtin/bytes.mbt @@ -176,21 +176,7 @@ pub fn FixedArray::blit_from_bytes( } ///| -/// Creates a new byte sequence by copying all bytes from the input sequence. -/// -/// Parameters: -/// -/// * `bytes` : The byte sequence to be copied. -/// -/// Returns a new `Bytes` containing the same sequence of bytes as the input. -/// -/// Example: -/// -/// ```moonbit -/// let original = b"\x01\x02\x03" -/// let copy = original.copy() -/// inspect(copy, content="b\"\\x01\\x02\\x03\"") -/// ``` +#deprecated("Bytes are immutable. Use `FixedArray::blit_from_bytes` if it's really necessary.") pub fn Bytes::copy(self : Bytes) -> Bytes { Bytes::makei(self.length(), fn(i) { self[i] }) } diff --git a/builtin/bytes_test.mbt b/builtin/bytes_test.mbt index 1dc528caa..04b4e3656 100644 --- a/builtin/bytes_test.mbt +++ b/builtin/bytes_test.mbt @@ -33,12 +33,6 @@ test "blit_from_string" { assert_eq(@bytes.from_fixedarray(bytes).to_unchecked_string(), str) } -///| -test "copy" { - let copy_bytes = HELLO_WORLD.copy() - assert_eq(copy_bytes.to_unchecked_string(), HELLO_WORLD.to_unchecked_string()) -} - ///| test "set_utf8_char (ASCII)" { let arr = FixedArray::makei(4, _ => b'\x00') @@ -149,7 +143,9 @@ test "set_utf16be_char" { ///| test "op_equal" { - let copy_bytes = HELLO_WORLD.copy() + let copy_bytes = FixedArray::make(HELLO_WORLD.length(), Byte::default()) + copy_bytes.blit_from_bytes(0, HELLO_WORLD, 0, HELLO_WORLD.length()) + let copy_bytes = Bytes::from_fixedarray(copy_bytes) assert_eq(HELLO_WORLD, copy_bytes) assert_not_eq(HELLO_WORLD, Bytes::new(10)) }