Docs

Vars

A var is a setting a service declares in crab.toml with a default, which each deployed copy sets to its own value, read with berm_lang::var.

A var is a setting whoever deploys a copy of a service chooses, such as the keywords a monitor watches. The service declares it with a default; each deployed copy holds its own value.

Declaring

[vars]
keywords = { default = "rust, wasm", description = "Words to watch on Hacker News" }
  • default is what a copy reads while it holds no value, "" when absent. description is shown where a deployer sets it.
  • A name is 1 to 64 ASCII letters, digits and _. A service declares at most 32, and a default holds at most 4096 bytes.
  • Variables belong to a deployment. Linking a service library does not inherit its variable declarations; declare any settings your service needs itself.
  • A var's name, description and default are part of the service's public interface: anyone who sees the service sees them, and crab inspect lists them.

Reading

let keywords = berm_lang::var("keywords")?;
let watched: Vec<&str> = keywords.split(',').map(str::trim).collect();
  • var(name) answers the value the copy holds, or the default while it holds none, as text.
  • Each var reads the value held when it is called, so a value set while a call runs reaches its next var.
  • A name [vars] does not declare is refused, and the ? fails the call.
  • A value is text: a list or a number is parsed by the service.

Values

Each deployed copy, on the local host and on Cloud, holds its own values. Only owners of its account set them and read them back.

Sets
Deploy The values typed on another account's service page, as the copy deploys. One left at its default is not set.
crab var set <service> <var> <value> One value.
crab var unset <service> <var> Back to its default.
crab var ls <service> Lists each var with its value or its default.
A deploy request's vars The values it names.
  • A deploy keeps every value it does not name. A copy holding no value reads the new default once a deploy changes it.
  • A deploy whose [vars] drops a var drops its value; declaring it again starts it from its default.
  • A value holds at most 4096 bytes. Setting a var the copy's version does not declare, or a longer value, is refused with E0011.
  • A var is never a secret: anyone who owns the copy reads its values. A key or credential is a secret.

Testing

berm_lang::test::var("keywords", "rust");
let out = berm_lang::test::call(berm_tool_scan, b"{}").unwrap();
berm_lang::test::forget();

Natively, test::var arranges what var answers; a var nothing arranged panics naming it, and test::forget clears them. On a host, a test deploys the service and sets values as an owner does. See Testing.