Skip to content

Typed access

Typed accessors walk the ordered Value tree:

let assert Ok(document) =
ccl.parse("server =\n host = localhost\n port = 8080\n")
let assert Ok("localhost") =
ccl.get_string(document, ["server", "host"])
let assert Ok(8080) =
ccl.get_int(document, ["server", "port"])

Available accessors are get_string, get_int, get_bool, get_float, get_list, and get_values.

Use get when the shape is not known in advance:

case ccl.get(document, ["server"]) {
Ok(ccl.ObjectValue(pairs)) -> inspect_server(pairs)
Ok(other) -> handle_other_shape(other)
Error(error) -> handle_get_error(error)
}

ObjectValue stores an ordered association list, not a dictionary. Source order survives the read.

The as_* functions read a Value you already hold. value_get walks further into it:

let assert Ok(server) = ccl.get(document, ["server"])
let assert Ok(port_value) = ccl.value_get(server, ["port"])
let assert Ok(8080) = ccl.as_int(port_value)

A non-negative decimal path segment indexes a list:

ports =
= 80
= 443
let assert Ok("80") = ccl.get_string(document, ["ports", "0"])

An invalid or missing path returns a GetError. It never falls back to a different shape silently.