Trait cell_map::Layer[][src]

pub trait Layer: Clone {
    const NUM_LAYERS: usize;
    const FIRST: Self;

    fn to_index(&self) -> usize;
fn from_index(index: usize) -> Self; }

Trait which defines the type of the layer index.

Layer indices should be enums which implement the Layer trait. By limiting indices to enums we can guarentee that all possible values of layer exist, and therefore do not have to provide run time checking that the layer exists within the map.

This is enforced by the use of the #[derive(Layer)] macro, which can only be implemented on enums.

Safety

Do not manually implement this trait for non-enum types, as CellMap will be unable to guarentee that the layer you’re attempting to access will be present in the map.

Example

use cell_map::Layer;

#[derive(Layer, Clone)]
enum MyLayer {
    Height,
    Gradient
}

Associated Constants

const NUM_LAYERS: usize[src]

Contains the total number of layers possible with this Layer

const FIRST: Self[src]

Contains the first layer variant

Loading content...

Required methods

fn to_index(&self) -> usize[src]

Maps each variant of the enum to a unique layer index, which can be used to get that layer from the map.

fn from_index(index: usize) -> Self[src]

Maps each layer index into a variant of the layer.

Safety

If the provided index doesn’t match a layer this function will panic.

Loading content...

Implementors

Loading content...