1///|
2pub fn type CStr ConstPtr[Byte]
CStr::(bytes : Bytes) -> (CStr, Rc[Bytes])
from_bytes(Bytes
bytes : Bytes
Bytes) -> (type CStr ConstPtr[Byte]
CStr, type Rc[T]
Rc[Bytes
Bytes]) {
3 if Bytes
bytes(Bytes, Int) -> Byte
Retrieves a byte at the specified index from a byte sequence.
Parameters:
bytes : The byte sequence to access.
index : The position in the byte sequence from which to retrieve the
byte.
Returns a byte value from the specified position in the sequence.
Throws a panic if the index is negative or greater than or equal to the
length of the byte sequence.
Example:
let bytes = b"\x01\x02\x03"
inspect(bytes[1], content="b'\\x02'")
[bytes.(self : Bytes) -> Int
Returns the number of bytes in a byte sequence.
Parameters:
bytes : The byte sequence whose length is to be determined.
Returns an integer representing the length (number of bytes) of the sequence.
Example:
let bytes = b"\x01\x02\x03"
inspect(bytes.length(), content="3")
let empty = b""
inspect(empty.length(), content="0")
length() (self : Int, other : Int) -> Int
Performs subtraction between two 32-bit integers, following standard two's
complement arithmetic rules. When the result overflows or underflows, it
wraps around within the 32-bit integer range.
Parameters:
self : The minuend (the number being subtracted from).
other : The subtrahend (the number to subtract).
Returns the difference between self and other.
Example:
let a = 42
let b = 10
inspect(a - b, content="32")
let max = 2147483647 // Int maximum value
inspect(max - -1, content="-2147483648") // Overflow case
- 1] (x : Byte, y : Byte) -> Bool
!= 0x00 {
4 (msg : String) -> Unit
Aborts the program with an error message. Always causes a panic, regardless
of the message provided.
Parameters:
message : A string containing the error message to be displayed when
aborting.
Returns a value of type T. However, this function never actually returns a
value as it always causes a panic.
abort("expected null-terminated byte strings")
5 }
6 let Rc[Bytes]
rc = type Rc[T]
Rc::(xs : Bytes) -> Rc[Bytes]
from_bytes(Bytes
bytes)
7 let CStr
cstr = Rc[Bytes]
rc |> (x : Rc[Bytes]) -> CStr
unsafe_coerce
8 (CStr
cstr, Rc[Bytes]
rc)
9}
10
11///|
12pub fn type CStr ConstPtr[Byte]
CStr::(ptr : Ptr[Byte]) -> CStr
unsafe_from_byte_ptr(Ptr[Byte]
ptr : type Ptr[T]
Ptr[Byte
Byte]) -> type CStr ConstPtr[Byte]
CStr {
13 (x : Ptr[Byte]) -> CStr
unsafe_coerce(Ptr[Byte]
ptr)
14}
15
16///|
17pub fn type CStr ConstPtr[Byte]
CStr::(ptr : ConstPtr[Byte]) -> CStr
unsafe_from_const_byte_ptr(ConstPtr[Byte]
ptr : type ConstPtr[T]
ConstPtr[Byte
Byte]) -> type CStr ConstPtr[Byte]
CStr {
18 (x : ConstPtr[Byte]) -> CStr
unsafe_coerce(ConstPtr[Byte]
ptr)
19}
20