Expand description

Helper macros for instantiating different kinds of algebraic types.

The following documentation applies to:

  • bounds!()
  • size!()
  • point!()
  • offset!()

Creating vector types

To create one of the aforementioned types, simply specify the components. The number of components determine the dimensions, for example

// This creates a Size2D, because we specified 2 arguments.
let very_big = size!(500, 500);

Exceptions

For Bounds2D it is the same, except the number of arguments are doubled.

// This creates a Bounds2D
let bounds = bounds!(0, 20, 10, 10);

Splat syntax

A type can be created with initalized values by specifying the value followed by a semicolon and the number of dimensions.

// This creates a Point2D where X and Y is `5`.
let point = point!(5; 2);

// This creates an Offset2D where X and Y is `0u8`.
let offset = offset!(u8; 2);

// No exception for bounds here, this is a Bounds2D.
let bounds = bounds!(10; 2);