Skip to content
Menu
Contents

Reading the tags

pure

Same arguments, same result; touches nothing outside.

pure if arg2 is

Pure when that argument is a pure function; otherwise as impure as it is.

impure

Reads or changes something outside the program.

WasiCli

1 type6 functions

The component target's command line: printing, reading stdin, arguments, environment variables and exiting over the WASI 0.2 CLI interfaces. The wasip1 package's WasiCli has the same names and types for all of these, so a program builds for either target. exit differs: this one reports only success or failure to the host, since wasi:cli/exit carries no other code. readLine reads a byte at a time, so that it consumes exactly the bytes it returns and a later read still sees the rest.

At a glance

  • Result

    Shorthand for [Ok(a) | Err(e)], the variant this module's fallible functions return.

  • print

    Write text to stdout as it is, with no newline added.

  • readAll

    Stdin to the end of input.

  • readLine

    One line of stdin, its terminator (\n, or \r\n) stripped.

  • args

    The program's arguments, its own name first.

  • env

    The value of the environment variable name, or Err(NotFound) when the environment has none.

  • exit

    Stop the program: 0 is success and any other code is failure.

Types

Result

Result(a, e) = [Ok(a) | Err(e)]

Shorthand for [Ok(a) | Err(e)], the variant this module's fallible functions return.

Functions

print

(String) -> Unitimpure

Write text to stdout as it is, with no newline added. A stream that fails or closes drops the rest of the text, as WasiCli.print drops a failed write.

readAll

() -> Stringimpure

Stdin to the end of input. Bytes that are not UTF-8 are replaced by U+FFFD, and a stream that fails ends the input where it stood.

readLine

() -> Result(String, [EndOfInput | e])impure

One line of stdin, its terminator (\n, or \r\n) stripped. An empty line is Ok(""), distinct from the Err(EndOfInput) a closed stdin gives, and a last line with no terminator is still Ok. It consumes exactly the bytes it returns, so a later readAll sees the rest.

args

() -> List(String)impure

The program's arguments, its own name first.

env

(String) -> Result(String, [NotFound | e])impure

The value of the environment variable name, or Err(NotFound) when the environment has none.

exit

(Int) -> aimpure

Stop the program: 0 is success and any other code is failure. Stable WASI 0.2.3 reports only which of the two it was, so the host's exit status is 0 or 1 whatever the nonzero code. Its exit-with-code is unstable, behind a feature hosts leave off by default (-S cli-exit-with-code in wasmtime).

Reading the tags

pure

Same arguments, same result; touches nothing outside.

pure if arg2 is

Pure when that argument is a pure function; otherwise as impure as it is.

impure

Reads or changes something outside the program.