componentized/directory

Synthetic sample. This package shows how the directory renders each WIT feature. It isn't published to any registry.

Records, variants, enums and flags.

Types

use type pair

from kitchen-sink:types/containers@0.1.0

use type maybe

from kitchen-sink:types/containers@0.1.0

record point

A point on a plane.

  • x: f64

    Across.

  • y: f64

    Down.

record labeled

A record of other types.

record empty-ish

  • only: bool

variant shape

A shape, with or without a payload.

  • dot

    A point has no size.

  • circle: f64
  • rectangle: tuple<point, point>
  • polygon: list<point>

enum direction

The cardinal directions.

  • north
  • east
  • south
  • west

flags permissions

A file's permissions.

  • read
  • write
  • execute

type heading

An alias of an alias.

Functions

functionarea: func(s: shape) -> f64

A block comment documents too.

functionturn: func(from: direction, quarter-turns: s8) -> direction

A keyword as a name, escaped with %.

functionallowed: func(have: permissions, want: permissions) -> bool

WIT

/// Records, variants, enums and flags.
interface shapes {
  use containers.{pair, maybe};

  /// A point on a plane.
  record point {
    /// Across.
    x: f64,
    /// Down.
    y: f64,
  }

  /// A record of other types.
  record labeled {
    label: maybe,
    at: point,
    tags: list<string>,
    pair: pair,
  }

  record empty-ish {
    only: bool,
  }

  /// A shape, with or without a payload.
  variant shape {
    /// A point has no size.
    dot,
    circle(f64),
    rectangle(tuple<point, point>),
    polygon(list<point>),
  }

  /// The cardinal directions.
  enum direction {
    north,
    east,
    south,
    west,
  }

  /// A file's permissions.
  flags permissions {
    read,
    write,
    execute,
  }

  /// An alias of an alias.
  type heading = direction;

  /// A block comment documents too.
  area: func(s: shape) -> f64;

  /// A keyword as a name, escaped with `%`.
  turn: func(%from: direction, quarter-turns: s8) -> direction;

  allowed: func(have: permissions, want: permissions) -> bool;
}