1///|
2extern "c" fn uv_os_uname(buffer : 
Bytes
Bytes
) ->
Int
Int
= "moonbit_uv_os_uname"
3 4///| 5struct Utsname { 6
String
sysname
:
String
String
7
String
release
:
String
String
8
String
version
:
String
String
9
String
machine
:
String
String
10} 11 12///| 13pub fn
struct Utsname {
  sysname: String
  release: String
  version: String
  machine: String
}
Utsname
::
(self : Utsname) -> String
sysname
(
Utsname
self
:
struct Utsname {
  sysname: String
  release: String
  version: String
  machine: String
}
Utsname
) ->
String
String
{
14
Utsname
self
.
String
sysname
15} 16 17///| 18pub fn
struct Utsname {
  sysname: String
  release: String
  version: String
  machine: String
}
Utsname
::
(self : Utsname) -> String
release
(
Utsname
self
:
struct Utsname {
  sysname: String
  release: String
  version: String
  machine: String
}
Utsname
) ->
String
String
{
19
Utsname
self
.
String
release
20} 21 22///| 23pub fn
struct Utsname {
  sysname: String
  release: String
  version: String
  machine: String
}
Utsname
::
(self : Utsname) -> String
version
(
Utsname
self
:
struct Utsname {
  sysname: String
  release: String
  version: String
  machine: String
}
Utsname
) ->
String
String
{
24
Utsname
self
.
String
version
25} 26 27///| 28pub fn
struct Utsname {
  sysname: String
  release: String
  version: String
  machine: String
}
Utsname
::
(self : Utsname) -> String
machine
(
Utsname
self
:
struct Utsname {
  sysname: String
  release: String
  version: String
  machine: String
}
Utsname
) ->
String
String
{
29
Utsname
self
.
String
machine
30} 31 32///| 33pub fn
() -> Utsname!Errno
os_uname
() ->
struct Utsname {
  sysname: String
  release: String
  version: String
  machine: String
}
Utsname
!
type! Errno Status
Errno
{
34 fn
(@bytes.View) -> String
decode
(
@bytes.View
bytes
:
type @bytes.View

A @bytes.View represents a view into a section of a Bytes without copying the data.

Example

let bs = b"\x00\x01\x02\x03\x04\x05"
let bv = bs[1:4]
assert_eq(bv.length(), 3)
assert_eq(bv[0], b'\x01')
assert_eq(bv[1], b'\x02')
assert_eq(bv[2], b'\x03')
@bytes.View
) ->
String
String
{
35 let
@buffer.T
buffer
=
(size_hint~ : Int = ..) -> @buffer.T

Creates a new extensible buffer with specified initial capacity. If the initial capacity is less than 1, the buffer will be initialized with capacity 1.

Parameters:

  • size_hint : Initial capacity of the buffer in bytes. Defaults to 0.

Returns a new buffer of type T.

Example:

test "new" {
  let buf = @buffer.new(size_hint=10)
  inspect(buf.length(), content="0")
  buf.write_string("test")
  inspect(buf.length(), content="8")
}
@buffer.new
()
36 for
Int
i
in
Int
0
..<
@bytes.View
bytes
.
(self : @bytes.View) -> Int

Returns the number of bytes in the view.

Parameters:

  • bytes_view : The view of a byte sequence.

Returns an integer representing the length of the view.

Example:

test "View::length" {
  let bytes = b"\x00\x01\x02\x03\x04"
  let view = bytes[2:4]
  inspect(view.length(), content="2")
}
length
() {
37 let
Byte
byte
=
@bytes.View
bytes
(@bytes.View, Int) -> Byte

Retrieves a byte from the view at the specified index.

Parameters:

  • self : The bytes view to retrieve the byte from.
  • index : The position in the view from which to retrieve the byte.

Returns the byte at the specified index if the index is valid.

Example:

test "View::op_get" {
  let bytes = b"\x01\x02\x03\x04\x05"
  let view = bytes[1:4] // view contains [0x02, 0x03, 0x04]
  inspect(view[1], content="b'\\x03'")
}

test "panic View::op_get/out_of_bounds" {
  let view = b"\x01\x02\x03"[:]
  ignore(view[3]) // Index out of bounds
}
[
i]
38 if
Byte
byte
(self : Byte, that : Byte) -> Bool

Compares two Byte values for equality.

Parameters:

  • self : The first Byte value to compare.
  • that : The second Byte value to compare.

Returns true if the two Byte values are equal, otherwise false.

==
0 {
39 break 40 } 41
@buffer.T
buffer
.
(self : @buffer.T, value : Byte) -> Unit

Writes a single byte to the end of the buffer. The buffer will automatically grow if necessary to accommodate the new byte.

Parameters:

  • buffer : The buffer to write to.
  • byte : The byte value to be written.

Example:

test "write_byte" {
  let buf = @buffer.new()
  buf.write_byte(b'\x41')
  inspect(buf.contents(), content="b\"\\x41\"")
}
write_byte
(
Byte
byte
)
42 } 43 return
(encoding~ : @encoding.Encoding, input : @bytes.View) -> String
@encoding.decode_lossy
(
@encoding.Encoding
encoding
=
@encoding.Encoding
UTF8
,
@buffer.T
buffer
.
(self : @buffer.T) -> Bytes

Returns a copy of the buffer's content as a sequence of bytes.

Parameters:

  • buffer : The buffer to read from.

Returns a Bytes object containing all bytes written to the buffer.

Example:

test "contents" {
  let buf = @buffer.new()
  buf.write_string("Test")
  inspect(
    buf.contents(),
    content=
      #|b"\x54\x00\x65\x00\x73\x00\x74\x00"
    ,
  )
}
contents
())
44 } 45 46 let
Bytes
buffer
=
(Int, Byte) -> Bytes
Bytes::
(len : Int, init : Byte) -> Bytes

Creates a new byte sequence of the specified length, where each byte is initialized to the given value. Returns an empty byte sequence if the length is negative.

Parameters:

  • length : The length of the byte sequence to create. Must be non-negative.
  • initial_value : The byte value used to initialize each position in the sequence.

Example:

test "Bytes::make" {
  let bytes = Bytes::make(3, b'\xFF')
  inspect(bytes, content=
  #|b"\xff\xff\xff"
)
  let empty = Bytes::make(0, b'\x00')
  inspect(empty, content="b\"\"")
}
make
(256
(self : Int, other : Int) -> Int

Multiplies two 32-bit integers. This is the implementation of the * operator for Int.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns the product of the two integers. If the result overflows the range of Int, it wraps around according to two's complement arithmetic.

Example:

test "Int::op_mul" {
  inspect(42 * 2, content="84")
  inspect(-10 * 3, content="-30")
  let max = 2147483647 // Int.max_value
  inspect(max * 2, content="-2") // Overflow wraps around
}
*
4, 0)
47 let
Int
status
=
(buffer : Bytes) -> Int
uv_os_uname
(
Bytes
buffer
)
48 if
Int
status
(self_ : Int, other : Int) -> Bool
<
0 {
49 raise
type! Errno Status
Errno
::
(errno : Int) -> Errno
of_int
(
Int
status
)
50 } 51 let
String
sysname
=
(@bytes.View) -> String
decode
([..
Bytes
buffer
[0:256]])
52 let
String
release
=
(@bytes.View) -> String
decode
([..
Bytes
buffer
[256:512]])
53 let
String
version
=
(@bytes.View) -> String
decode
([..
Bytes
buffer
[512:768]])
54 let
String
machine
=
(@bytes.View) -> String
decode
([..
Bytes
buffer
[768:1024]])
55 {
String
sysname
,
String
release
,
String
version
,
String
machine
}
56} 57