Trait DefaultsArray

Source
pub trait DefaultsArray {
    // Provided method
    fn defaults<const N: usize>() -> [Self; N]
       where Self: Default { ... }
}
Expand description

Used when we need a collection of default type instances e.g. when creating a default bank we need 16 default patterns.

// usage example

use ot_tools_io::DefaultsArray;

struct SomeType {
    x: u8,
}

impl Default for SomeType {
    fn default() -> Self {
        Self { x: 0 }
    }
}

impl DefaultsArray for SomeType {}

let xs: [SomeType; 20] = SomeType::defaults();
assert_eq!(xs.len(), 20);

let xs = SomeType::defaults::<25>();
assert_eq!(xs.len(), 25);

Provided Methods§

Source

fn defaults<const N: usize>() -> [Self; N]
where Self: Default,

Create an Array containing N default instances of Self.

Implementors§