bool8

PropertyValue
Size1 byte (8 bits) — a language guarantee, not platform-dependent
Valuesfalse or true

bool8 is the everyday boolean type, and the plain bool keyword is an alias for it. Like every Rux boolean type it stores only true or false, regardless of its underlying width; the extra bits are zeroed and reserved. Booleans are distinct from integers — no implicit conversion happens in either direction, and a condition in if, while, or for must already be a boolean expression.

Use bool8 (i.e. bool) for flags, conditions, and return values in everyday code; reserve the wider boolean types for SIMD, FFI, and memory-layout-sensitive contexts.

Literals

There are exactly two boolean literals, both lowercase keywords:

let a: bool8 = true;
let b: bool8 = false;

They are widened to the target type on assignment and cannot stand in for integer values — let n: int32 = true; is a compile-time error.

Typical Use Cases

  • Flags, conditions, and control flow
  • Function return values that answer yes/no questions
  • Struct fields where one byte of storage is enough

Logical Operations

These operators work on single boolean values and short-circuit where applicable.

OperatorNameDescription
&&Logical ANDtrue only if both operands are true
||Logical ORtrue if at least one operand is true
!Logical NOTInverts the boolean value
let a: bool8 = true;
let b: bool8 = false;

let andResult = a && b;  // false
let orResult  = a || b;  // true
let notResult = !a;      // false

Short-circuit evaluation applies: in a && b, if a is false, b is never evaluated; in a || b, if a is true, b is never evaluated. Prefer &&, ||, and ! over the bitwise operators below for general logic — they short-circuit and read more clearly.

Bitwise Operations

bool8 also supports non-short-circuiting bitwise operators, which always evaluate both operands.

OperatorName
&Bitwise AND
|Bitwise OR
^Bitwise XOR
~Bitwise NOT
let a: bool8 = true;
let b: bool8 = false;

let c = a & b;  // false
let d = a | b;  // true
let e = a ^ b;  // true
let f = ~a;     // false

Comparison

OperatorDescriptionResult
==Equalbool
!=Not equalbool
let a: bool8 = true;
let b: bool8 = true;

let eq  = a == b;  // true
let neq = a != b;  // false

Booleans support equality but not ordering (<, >, <=, >=). Convert to an integer first if ordered comparison is needed.

Conversion

Conversions between boolean and numeric types are always explicit, using as:

let flag: bool8 = true;
let n = flag as int32;        // 1   — true → 1, false → 0
let back = n as bool;         // true — non-zero → true, zero → false
let wide = flag as bool512;   // boolean widths convert with as

true converts to 1 and false to 0 for any integer type; any non-zero integer converts to true and zero to false. Conversions between boolean widths preserve the logical value (true/false); the extra bits are discarded or zeroed accordingly. Prefer an explicit comparison (count > 0) over count as bool when deriving a boolean from a number — it makes the intent clear and avoids masking logic errors.

See Also

  • bool — the alias keyword for this type
  • bool16 — the next width up