Skip to content

Commit 0741832

Browse files
refactor(builtin): make BytesView escape_to private and generic over Logger
Address review comments on PR #4196: BytesView::escape_to and its helper write_byte_hex are internal (used only by the Show and ToJson impls in this package), so drop pub, and genericize them over [T : Logger] so writes dispatch statically where a concrete logger is passed. Regenerate pkg.generated.mbti (the pub entry is gone). Co-Authored-By: SeekMoon <seekmoon@moonbitlang.com>
1 parent da04c8b commit 0741832

2 files changed

Lines changed: 2 additions & 3 deletions

File tree

builtin/bytesview.mbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ pub fn BytesView::iter2(self : BytesView) -> Iter2[Int, Byte] {
331331
}
332332

333333
///|
334-
fn write_byte_hex(logger : &Logger, byte : Byte) -> Unit {
334+
fn[T : Logger] write_byte_hex(logger : T, byte : Byte) -> Unit {
335335
fn hex_digit(value : Int) -> Char {
336336
if value < 10 {
337337
(value + '0'.to_int()).unsafe_to_char()
@@ -349,7 +349,7 @@ fn write_byte_hex(logger : &Logger, byte : Byte) -> Unit {
349349
/// Writes the bytes with printable ASCII kept as-is and everything else
350350
/// rendered as `\xHH`, without the surrounding `b"`/`"`. Shared by `Show`,
351351
/// which adds the quotes, and `ToJson`, which does not.
352-
pub fn BytesView::escape_to(self : BytesView, logger : &Logger) -> Unit {
352+
fn[T : Logger] BytesView::escape_to(self : BytesView, logger : T) -> Unit {
353353
for byte in self {
354354
if byte is (b' '..=b'~') && byte != b'"' && byte != b'\\' {
355355
logger.write_char(byte.to_char())

builtin/pkg.generated.mbti

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,6 @@ pub fn BytesView::compare(Self, Self) -> Int
11701170
pub fn BytesView::data(Self) -> Bytes
11711171
pub fn BytesView::equal(Self, Self) -> Bool
11721172
pub fn BytesView::equal_to_bytes(Self, Bytes) -> Bool
1173-
pub fn BytesView::escape_to(Self, &Logger) -> Unit
11741173
pub fn BytesView::find(Self, Self) -> Int?
11751174
pub fn BytesView::get(Self, Int) -> Byte?
11761175
pub fn BytesView::get_view(Self, start? : Int, end? : Int) -> Self?

0 commit comments

Comments
 (0)