Primitive type auto-imported

unit

type unit
Source: compiler/src/builtin_docs/types.hy

The type with a single value, (), used where there is no meaningful value.

A function with no -> return type returns unit, and statements have type unit. It is also written void (for example as an FFI return type). Result<unit, E> is the usual result of an operation that can fail but returns nothing.

Examples#

use tests::assert;
fn check(int n) -> Result<unit, string> {
    if n < 0 {
        raise "negative";
    }
    return ();
}

fn main() {
    let ok = match check(1) {
        Result::Ok(_) => true,
        Result::Err(_) => false,
    };
    assert!(ok);
}

See also#

  • Result
  • int: A 64-bit signed integer, from -9223372036854775808 to 9223372036854775807.
  • float: A 64-bit IEEE-754 floating-point number.
  • bool: A boolean: true or false.
  • byte: An unsigned 8-bit integer in 0..=255.
  • string: A UTF-8 text string.
↑ ↓ navigate ↵ open