componentized/directory

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

Resources and each kind of function on them.

Types

use record point

from kitchen-sink:types/shapes@0.1.0

A point on a plane.

  • x: f64

    Across.

  • y: f64

    Down.

resource token

A resource with no functions.

resource canvas

A resource with every kind of member.

  • constructor functionconstructor(width: u32, height: u32)

    Makes an empty canvas.

  • functionplot: func(at: point, color: list<u8, 4>)

    A method.

  • functioncopy-from: func(other: borrow<canvas>) -> result<_, string>

    A method that borrows another canvas.

  • functionsnapshot: func() -> canvas

    A method that hands back a resource it owns.

  • async functionrender: async func() -> list<u8>

    An async method.

  • static functionopen: static func(path: string) -> result<canvas, string>

    A static function.

  • static async functionload: static async func(url: string) -> result<canvas, string>

    A static async function.

  • get functiontitle: get() -> string

    A property with a getter and a setter.

  • set functiontitle: set(value: string)
  • get functionarea: get() -> u64

    A property with a getter alone.

  • static get functionmax-size: static get() -> u32

    A static property.

  • static set functionmax-size: static set(value: u32) -> result<_, string>

Functions

functionmerge: func(a: canvas, b: borrow<canvas>) -> canvas

A free function taking and returning resources.

functionissue: func() -> token

A free function that names the resource without own.

WIT

/// Resources and each kind of function on them.
interface resources {
  use shapes.{point};

  /// A resource with no functions.
  resource token;

  /// A resource with every kind of member.
  resource canvas {
    /// Makes an empty canvas.
    constructor(width: u32, height: u32);
    /// A method.
    plot: func(at: point, color: list<u8, 4>);
    /// A method that borrows another canvas.
    copy-from: func(other: borrow<canvas>) -> result<_, string>;
    /// A method that hands back a resource it owns.
    snapshot: func() -> canvas;
    /// An async method.
    render: async func() -> list<u8>;
    /// A static function.
    open: static func(path: string) -> result<canvas, string>;
    /// A static async function.
    load: static async func(url: string) -> result<canvas, string>;
    /// A property with a getter and a setter.
    title: get() -> string;
    title: set(value: string);
    /// A property with a getter alone.
    area: get() -> u64;
    /// A static property.
    max-size: static get() -> u32;
    max-size: static set(value: u32) -> result<_, string>;
  }

  /// A free function taking and returning resources.
  merge: func(a: canvas, b: borrow<canvas>) -> canvas;

  /// A free function that names the resource without `own`.
  issue: func() -> token;
}