Skip to content

types

Built-in value types and the methods callable on them.

Types

any

Any type (accepts all values)

any methods

to_string on any
to_string()

Convert to string

AsyncChannelReceiver

Native async-runtime channel receiver returned by `channel(n)`.

AsyncChannelReceiver methods

recv on AsyncChannelReceiver
recv()

Receive, parking until a value arrives or the channel closes

try_recv on AsyncChannelReceiver
try_recv()

Immediate receive attempt

recv_timeout on AsyncChannelReceiver
recv_timeout(ms)

Receive with timeout

close on AsyncChannelReceiver
close()

Close the receiver

to_string on AsyncChannelReceiver
to_string()

Convert to string

AsyncChannelSender

Native async-runtime channel sender returned by `channel(n)`.

AsyncChannelSender methods

send on AsyncChannelSender
send(value)

Send, parking if the channel is full

close on AsyncChannelSender
close()

Close the sender

to_string on AsyncChannelSender
to_string()

Convert to string

AsyncTask

Native async-runtime task handle returned by `spawn`.

AsyncTask methods

await on AsyncTask
task.await

Wait for task

to_string on AsyncTask
to_string()

Convert to string

bool

Boolean type

bool methods

to_string on bool
to_string()

Convert to string

bytes

Byte string type

bytes methods

len on bytes
len()

Number of bytes

is_empty on bytes
is_empty()

True if empty

bytes on bytes
bytes()

Identity byte representation

contains on bytes
contains(byte_or_bytes)

Contains byte value or sequence

find on bytes
find(byte_or_bytes)

Index of first occurrence

count on bytes
count(byte_or_bytes)

Count non-overlapping occurrences

starts_with on bytes
starts_with(prefix)

Starts with prefix

ends_with on bytes
ends_with(suffix)

Ends with suffix

slice on bytes
slice(start, end?)

Sub-slice

split on bytes
split(sep)

Split by byte value or bytes separator

replace on bytes
replace(from, to)

Replace byte value or bytes sequence

reverse on bytes
reverse()

Reversed copy

repeat on bytes
repeat(n)

Repeat n times

push on bytes
push(byte)

Append byte, returning new bytes

extend on bytes
extend(other)

Append bytes, returning new bytes

set on bytes
set(index, byte)

Replace byte at index, returning new bytes

pop on bytes
pop()

Return (bytes_without_last, Option<byte>)

to_list on bytes
to_list()

Convert to list

to_str on bytes
to_str()

Decode as UTF-8

to_hex on bytes
to_hex()

Hex-encoded string

to_base64 on bytes
to_base64()

Base64-encoded string

to_string on bytes
to_string()

Convert to string

read_u16_le on bytes
read_u16_le(offset)

Read unsigned 16-bit little-endian integer

read_u16_be on bytes
read_u16_be(offset)

Read unsigned 16-bit big-endian integer

read_u32_le on bytes
read_u32_le(offset)

Read unsigned 32-bit little-endian integer

read_u32_be on bytes
read_u32_be(offset)

Read unsigned 32-bit big-endian integer

read_u64_le on bytes
read_u64_le(offset)

Read unsigned 64-bit little-endian integer if it fits in int

read_u64_be on bytes
read_u64_be(offset)

Read unsigned 64-bit big-endian integer if it fits in int

read_i16_le on bytes
read_i16_le(offset)

Read signed 16-bit little-endian integer

read_i16_be on bytes
read_i16_be(offset)

Read signed 16-bit big-endian integer

read_i32_le on bytes
read_i32_le(offset)

Read signed 32-bit little-endian integer

read_i32_be on bytes
read_i32_be(offset)

Read signed 32-bit big-endian integer

read_i64_le on bytes
read_i64_le(offset)

Read signed 64-bit little-endian integer

read_i64_be on bytes
read_i64_be(offset)

Read signed 64-bit big-endian integer

cell

Mutable reference cell type

cell methods

get on cell
get()

Read cell value

set on cell
set(val)

Set cell value

update on cell
update(fn)

Apply fn to the current value, store it, and return it

to_string on cell
to_string()

Convert to string

Channel

Bounded async channel created by `channel(n)`. Requires the `concurrency` feature.

Channel methods

send on Channel
send(val)

Send value

recv on Channel
recv()

Receive value

try_recv on Channel
try_recv()

Non-blocking receive

recv_timeout on Channel
recv_timeout(ms)

Receive with timeout

close on Channel
close()

Close channel

to_string on Channel
to_string()

Convert to string

dict

Dictionary type (e.g. dict<string, int>)

dict methods

len on dict
len()

Number of entries

is_empty on dict
is_empty()

True if empty

keys on dict
keys()

List of keys

values on dict
values()

List of values

entries on dict
entries()

List of (key, value) tuples

contains_key on dict
contains_key(key)

Key exists

get on dict
get(key)

Get value by key

insert on dict
insert(key, val)

Insert entry

remove on dict
remove(key)

Remove entry (dict) or element (set)

merge on dict
merge(other)

Merge dicts

update on dict
update(other)

Merge dict (mutating)

map on dict
map(fn)

Apply fn(key, value) to each entry and keep keys

filter on dict
filter(fn)

Keep entries where fn(key, value) is truthy

keys_of on dict
keys_of(val)

Keys with matching value

zip on dict
zip(other)

Merge matching keys into tuples

to_string on dict
to_string()

Convert to string

float

Floating-point type

float methods

to_string on float
to_string()

Convert to string

fn

Function type

fn methods

to_string on fn
to_string()

Convert to string

int

Integer type

int methods

to_string on int
to_string()

Convert to string

list

List type (e.g. list<int>)

list methods

len on list
len()

Number of elements

is_empty on list
is_empty()

True if empty

contains on list
contains(val)

Contains value

push on list
push(val)

Append value

pop on list
pop()

Remove last element

first on list
first()

First element (Option)

last on list
last()

Last element (Option)

reverse on list
reverse()

Reversed copy

sort on list
sort()

Sorted copy

sort_by on list
sort_by(fn)

Sort by key function

flatten on list
flatten()

Flatten one level

join on list
join(sep)

Join with separator

enumerate on list
enumerate()

Index-value tuples

zip on list
zip(other)

Zip with another list

map on list
map(fn)

Apply function

filter on list
filter(fn)

Keep matching elements

fold on list
fold(init, fn)

Reduce with accumulator

flat_map on list
flat_map(fn)

Map then flatten

any on list
any(fn)

True if any match

all on list
all(fn)

True if all match

index on list
index(val)

Index of first occurrence

count on list
count(val)

Count occurrences

slice on list
slice(start, end?)

Sublist by index

dedup on list
dedup()

Remove consecutive duplicates

unique on list
unique()

Remove all duplicates

sum on list
sum()

Sum of elements

window on list
window(n)

Sliding windows of size n

chunk on list
chunk(n)

Split into chunks of size n

reduce on list
reduce(fn)

Reduce list with fn (no initial value)

min on list
min()

Minimum element

max on list
max()

Maximum element

to_string on list
to_string()

Convert to string

Option

Option type (e.g. Option<int>)

Variants: Some, None

Option methods

is_some on Option
is_some()

True if Some

is_none on Option
is_none()

True if None

unwrap on Option
unwrap()

Extract value or error

unwrap_or on Option
unwrap_or(default)

Unwrap or return default

expect on Option
expect(msg)

Unwrap or error

map on Option
map(fn)

Apply fn to the inner value if Some

and_then on Option
and_then(fn)

Flat-map if Some

or_else on Option
or_else(fn)

Call fn if None

unwrap_or_else on Option
unwrap_or_else(fn)

Unwrap or call fn if None

to_string on Option
to_string()

Convert to string

range

Range type

range methods

len on range
len()

Number of values in the range

contains on range
contains(int)

True if the value is in range

to_list on range
to_list()

Materialize the range as a list

to_string on range
to_string()

Convert to string

Result

Result type (e.g. Result<int, string>)

Variants: Ok, Err

Result methods

is_ok on Result
is_ok()

True if Ok

is_err on Result
is_err()

True if Err

unwrap on Result
unwrap()

Extract Ok value or error

unwrap_or on Result
unwrap_or(default)

Unwrap or return default

expect on Result
expect(msg)

Unwrap or error with message

map on Result
map(fn)

Apply fn to the Ok value

map_err on Result
map_err(fn)

Transform error

and_then on Result
and_then(fn)

Flat-map on Ok

or_else on Result
or_else(fn)

Call fn on Err

unwrap_or_else on Result
unwrap_or_else(fn)

Unwrap or call fn with the error

to_string on Result
to_string()

Convert to string

set

Set type

set methods

len on set
len()

Number of elements

contains on set
contains(val)

Contains value

is_empty on set
is_empty()

True if empty

add on set
add(val)

Add element to set

remove on set
remove(val)

Remove element from set

union on set
union(other)

Union of two sets

intersection on set
intersection(other)

Intersection of two sets

difference on set
difference(other)

Difference of two sets

to_list on set
to_list()

Convert to list

to_string on set
to_string()

Convert to string

string

String type

string methods

len on string
len()

Length

is_empty on string
is_empty()

True if empty

contains on string
contains(sub)

Contains substring/element

starts_with on string
starts_with(prefix)

Starts with prefix

ends_with on string
ends_with(suffix)

Ends with suffix

trim on string
trim()

Strip whitespace

trim_start on string
trim_start()

Trim leading whitespace

trim_end on string
trim_end()

Trim trailing whitespace

split on string
split(delim)

Split by delimiter

replace on string
replace(from, to)

Replace occurrences

to_upper on string
to_upper()

Uppercase

to_lower on string
to_lower()

Lowercase

chars on string
chars()

List of characters

char_len on string
char_len()

Character count (Unicode-aware)

reverse on string
reverse()

Reversed copy

find on string
find(sub)

Index of first occurrence

index on string
index(sub)

Alias for find(sub)

count on string
count(sub)

Count non-overlapping occurrences

repeat on string
repeat(n)

Repeat n times

slice on string
slice(start, end?)

Substring by character index

bytes on string
bytes()

List of byte values

to_int on string
to_int()

Parse as integer

to_float on string
to_float()

Parse as float

to_string on string
to_string()

Convert to string

pad_start on string
pad_start(width, char)

Pad start to width

pad_end on string
pad_end(width, char)

Pad end to width

strip_prefix on string
strip_prefix(prefix)

Remove prefix if present

strip_suffix on string
strip_suffix(suffix)

Remove suffix if present

Task

Async task handle returned by `spawn`. Requires the `concurrency` feature.

Task methods

await on Task
task.await

Wait for task

is_finished on Task
is_finished()

Check if done

cancel on Task
cancel()

Cancel task

is_cancelled on Task
is_cancelled()

Check if cancelled

await_timeout on Task
await_timeout(ms)

Wait up to ms and return Option

to_string on Task
to_string()

Convert to string

tuple

Tuple type

tuple methods

len on tuple
len()

Number of elements

contains on tuple
contains(val)

Contains value

to_list on tuple
to_list()

Convert to list

to_string on tuple
to_string()

Convert to string

Documentation reflects Ion v0.2.0-66-g3faa376.