8000 chore(bytes): deprecate Bytes::copy by peter-jerry-ye · Pull Request #2303 · moonbitlang/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chore(bytes): deprecate Bytes::copy #2303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions builtin/builtin.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 1 addition & 15 deletions builtin/bytes.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -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] })
}
Expand Down
10 changes: 3 additions & 7 deletions builtin/bytes_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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))
}
Expand Down
0