Trait State

Source
pub trait State:
    Sized
    + Clone
    + Default
    + Send
    + Sync
    + Debug {
    // Required methods
    fn subdivide(&self, subdivisions: usize) -> Vec<Self>;
    fn merge(states: &[Self]) -> Self;

    // Provided method
    fn super_state_at_level(&self, dimensions: usize, level: usize) -> Self { ... }
}
Expand description

Trait that describes QDF space state.

§Examples

use quantized_density_fields::State;
use std::iter::repeat;

#[derive(Debug, Default, Eq, PartialEq, Clone)]
struct Integer(i32);

impl State for Integer {
    fn subdivide(&self, subdivisions: usize) -> Vec<Self> {
        repeat(Integer(self.0 / subdivisions as i32)).take(subdivisions).collect()
    }
    fn merge(states: &[Self]) -> Self {
        Integer(states.iter().map(|v| v.0).sum())
    }
}

let substates = Integer(16).subdivide(4);
assert_eq!(substates, vec![Integer(4), Integer(4), Integer(4), Integer(4)]);
let state = State::merge(&substates);
assert_eq!(state, Integer(16));

Required Methods§

Source

fn subdivide(&self, subdivisions: usize) -> Vec<Self>

Create data template that we get by subdivision of source data.

§Arguments
  • subdivisions - number of subdivisions.
Source

fn merge(states: &[Self]) -> Self

Merge multiple data instances into one.

§Arguments
  • states - list of source data to merge.

Provided Methods§

Source

fn super_state_at_level(&self, dimensions: usize, level: usize) -> Self

Multiply and merge multiple instances of itself into one super state.

§Arguments
  • dimensions - number of dimensions.
  • level - number level at which you merge.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl State for f32

Source§

fn subdivide(&self, subdivisions: usize) -> Vec<Self>

Source§

fn merge(states: &[Self]) -> Self

Source§

impl State for f64

Source§

fn subdivide(&self, subdivisions: usize) -> Vec<Self>

Source§

fn merge(states: &[Self]) -> Self

Source§

impl State for i8

Source§

fn subdivide(&self, subdivisions: usize) -> Vec<Self>

Source§

fn merge(states: &[Self]) -> Self

Source§

impl State for i16

Source§

fn subdivide(&self, subdivisions: usize) -> Vec<Self>

Source§

fn merge(states: &[Self]) -> Self

Source§

impl State for i32

Source§

fn subdivide(&self, subdivisions: usize) -> Vec<Self>

Source§

fn merge(states: &[Self]) -> Self

Source§

impl State for i64

Source§

fn subdivide(&self, subdivisions: usize) -> Vec<Self>

Source§

fn merge(states: &[Self]) -> Self

Source§

impl State for isize

Source§

fn subdivide(&self, subdivisions: usize) -> Vec<Self>

Source§

fn merge(states: &[Self]) -> Self

Source§

impl State for u8

Source§

fn subdivide(&self, subdivisions: usize) -> Vec<Self>

Source§

fn merge(states: &[Self]) -> Self

Source§

impl State for u16

Source§

fn subdivide(&self, subdivisions: usize) -> Vec<Self>

Source§

fn merge(states: &[Self]) -> Self

Source§

impl State for u32

Source§

fn subdivide(&self, subdivisions: usize) -> Vec<Self>

Source§

fn merge(states: &[Self]) -> Self

Source§

impl State for u64

Source§

fn subdivide(&self, subdivisions: usize) -> Vec<Self>

Source§

fn merge(states: &[Self]) -> Self

Source§

impl State for usize

Source§

fn subdivide(&self, subdivisions: usize) -> Vec<Self>

Source§

fn merge(states: &[Self]) -> Self

Implementors§