1///|
2/// `str2bytes` encodes a UTF-16 `String` as a UTF-8 `Bytes`.
3///
4/// Examples:
5/// ```
6/// inspect!(str2bytes("+/ Hello, δΈ–η•Œ! 🌍"), content=
7///   #|b"\x2b\x2f\x20\x48\x65\x6c\x6c\x6f\x2c\x20\xe4\xb8\x96\xe7\x95\x8c\x21\x20\xf0\x9f\x8c\x8d"
8/// )
9/// ```
10pub fn 
(s : String) -> Bytes

str2bytes encodes a UTF-16 String as a UTF-8 Bytes.

Examples:

inspect!(str2bytes("+/ Hello, δΈ–η•Œ! 🌍"), content=
  #|b"\x2b\x2f\x20\x48\x65\x6c\x6c\x6f\x2c\x20\xe4\xb8\x96\xe7\x95\x8c\x21\x20\xf0\x9f\x8c\x8d"
)
str2bytes
(
String
s
:
String
String
) ->
Bytes
Bytes
{
11
String
s
.
(self : String) -> Iter[Char]

Returns an iterator over the Unicode characters in the string.

Note: This iterator yields Unicode characters, not Utf16 code units. As a result, the count of characters returned by iter().count() may not be equal to the length of the string returned by length().

let s = "Hello, World!🀣";
assert_eq(s.iter().count(), 14); // Unicode characters
assert_eq(s.length(), 15); // Utf16 code units
iter
() |>
(string : Iter[Char]) -> Iter[Byte]
@encoder.utf8
() |>
(Iter[Byte]) -> Bytes
Bytes::from_iter
()
12} 13 14///| 15test "str2bytes works on simple case" { 16 let
Bytes
got
=
(s : String) -> Bytes

str2bytes encodes a UTF-16 String as a UTF-8 Bytes.

Examples:

inspect!(str2bytes("+/ Hello, δΈ–η•Œ! 🌍"), content=
  #|b"\x2b\x2f\x20\x48\x65\x6c\x6c\x6f\x2c\x20\xe4\xb8\x96\xe7\x95\x8c\x21\x20\xf0\x9f\x8c\x8d"
)
str2bytes
("simple case")
17
(obj : &Show, content~ : String, loc~ : SourceLoc = _, args_loc~ : ArgsLoc = _) -> Unit!InspectError

Tests if the string representation of an object matches the expected content. Used primarily in test cases to verify the correctness of Show implementations and program outputs.

Parameters:

  • object : The object to be inspected. Must implement the Show trait.
  • content : The expected string representation of the object. Defaults to an empty string.
  • location : Source code location information for error reporting. Automatically provided by the compiler.
  • arguments_location : Location information for function arguments in source code. Automatically provided by the compiler.

Throws an InspectError if the actual string representation of the object does not match the expected content. The error message includes detailed information about the mismatch, including source location and both expected and actual values.

Example:

test "inspect/basic" {
  inspect(42, content="42")
  inspect("hello", content="hello")
  inspect([1, 2, 3], content="[1, 2, 3]")
}
inspect
!(
18
Bytes
got
,
19
String
content
=
20 #|b"\x73\x69\x6d\x70\x6c\x65\x20\x63\x61\x73\x65" 21 , 22 ) 23
(obj : &Show, content~ : String, loc~ : SourceLoc = _, args_loc~ : ArgsLoc = _) -> Unit!InspectError

Tests if the string representation of an object matches the expected content. Used primarily in test cases to verify the correctness of Show implementations and program outputs.

Parameters:

  • object : The object to be inspected. Must implement the Show trait.
  • content : The expected string representation of the object. Defaults to an empty string.
  • location : Source code location information for error reporting. Automatically provided by the compiler.
  • arguments_location : Location information for function arguments in source code. Automatically provided by the compiler.

Throws an InspectError if the actual string representation of the object does not match the expected content. The error message includes detailed information about the mismatch, including source location and both expected and actual values.

Example:

test "inspect/basic" {
  inspect(42, content="42")
  inspect("hello", content="hello")
  inspect([1, 2, 3], content="[1, 2, 3]")
}
inspect
!(
24
(s : String) -> Bytes

str2bytes encodes a UTF-16 String as a UTF-8 Bytes.

Examples:

inspect!(str2bytes("+/ Hello, δΈ–η•Œ! 🌍"), content=
  #|b"\x2b\x2f\x20\x48\x65\x6c\x6c\x6f\x2c\x20\xe4\xb8\x96\xe7\x95\x8c\x21\x20\xf0\x9f\x8c\x8d"
)
str2bytes
("+/ Hello, δΈ–η•Œ! 🌍"),
25
String
content
=
26 #|b"\x2b\x2f\x20\x48\x65\x6c\x6c\x6f\x2c\x20\xe4\xb8\x96\xe7\x95\x8c\x21\x20\xf0\x9f\x8c\x8d" 27 , 28 ) 29} 30 31///| 32/// `str2array` encodes a UTF-16 `String` as a UTF-8 `Array[Byte]`. 33/// This is a more convenient version of `str2bytes` for when you want an `Array[Byte]`. 34/// 35/// Examples: 36/// ``` 37/// inspect!(str2array("🌍"), content="[b'\\xF0', b'\\x9F', b'\\x8C', b'\\x8D']") 38/// ``` 39pub fn
(s : String) -> Array[Byte]

str2array encodes a UTF-16 String as a UTF-8 Array[Byte]. This is a more convenient version of str2bytes for when you want an Array[Byte].

Examples:

inspect!(str2array("🌍"), content="[b'\\xF0', b'\\x9F', b'\\x8C', b'\\x8D']")
str2array
(
String
s
:
String
String
) ->
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
[
Byte
Byte
] {
40
String
s
.
(self : String) -> Iter[Char]

Returns an iterator over the Unicode characters in the string.

Note: This iterator yields Unicode characters, not Utf16 code units. As a result, the count of characters returned by iter().count() may not be equal to the length of the string returned by length().

let s = "Hello, World!🀣";
assert_eq(s.iter().count(), 14); // Unicode characters
assert_eq(s.length(), 15); // Utf16 code units
iter
() |>
(string : Iter[Char]) -> Iter[Byte]
@encoder.utf8
() |>
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
(Iter[Byte]) -> Array[Byte]

Creates a new array containing all elements from an iterator.

Parameters:

  • iterator : An iterator containing elements of type T.

Returns a new array containing all elements from the iterator in the same order.

Example:

test "Array::from_iter" {
  let iter = Iter::singleton(42)
  let arr = Array::from_iter(iter)
  inspect(arr, content="[42]")
}
::from_iter
()
41} 42 43///| 44test "str2array works on simple case" { 45 let
Array[Byte]
got
=
(s : String) -> Array[Byte]

str2array encodes a UTF-16 String as a UTF-8 Array[Byte]. This is a more convenient version of str2bytes for when you want an Array[Byte].

Examples:

inspect!(str2array("🌍"), content="[b'\\xF0', b'\\x9F', b'\\x8C', b'\\x8D']")
str2array
("simple case")
46
(obj : &Show, content~ : String, loc~ : SourceLoc = _, args_loc~ : ArgsLoc = _) -> Unit!InspectError

Tests if the string representation of an object matches the expected content. Used primarily in test cases to verify the correctness of Show implementations and program outputs.

Parameters:

  • object : The object to be inspected. Must implement the Show trait.
  • content : The expected string representation of the object. Defaults to an empty string.
  • location : Source code location information for error reporting. Automatically provided by the compiler.
  • arguments_location : Location information for function arguments in source code. Automatically provided by the compiler.

Throws an InspectError if the actual string representation of the object does not match the expected content. The error message includes detailed information about the mismatch, including source location and both expected and actual values.

Example:

test "inspect/basic" {
  inspect(42, content="42")
  inspect("hello", content="hello")
  inspect([1, 2, 3], content="[1, 2, 3]")
}
inspect
!(
47
Array[Byte]
got
,
48
String
content
="[b'\\x73', b'\\x69', b'\\x6D', b'\\x70', b'\\x6C', b'\\x65', b'\\x20', b'\\x63', b'\\x61', b'\\x73', b'\\x65']",
49 ) 50
(obj : &Show, content~ : String, loc~ : SourceLoc = _, args_loc~ : ArgsLoc = _) -> Unit!InspectError

Tests if the string representation of an object matches the expected content. Used primarily in test cases to verify the correctness of Show implementations and program outputs.

Parameters:

  • object : The object to be inspected. Must implement the Show trait.
  • content : The expected string representation of the object. Defaults to an empty string.
  • location : Source code location information for error reporting. Automatically provided by the compiler.
  • arguments_location : Location information for function arguments in source code. Automatically provided by the compiler.

Throws an InspectError if the actual string representation of the object does not match the expected content. The error message includes detailed information about the mismatch, including source location and both expected and actual values.

Example:

test "inspect/basic" {
  inspect(42, content="42")
  inspect("hello", content="hello")
  inspect([1, 2, 3], content="[1, 2, 3]")
}
inspect
!(
51
(s : String) -> Array[Byte]

str2array encodes a UTF-16 String as a UTF-8 Array[Byte]. This is a more convenient version of str2bytes for when you want an Array[Byte].

Examples:

inspect!(str2array("🌍"), content="[b'\\xF0', b'\\x9F', b'\\x8C', b'\\x8D']")
str2array
("🌍"),
52
String
content
="[b'\\xF0', b'\\x9F', b'\\x8C', b'\\x8D']",
53 ) 54} 55