Module peroxide::traits::pointer

source ·
Expand description

Pointer toolbox

§Redox

§Type

pub struct Redox<T: Vector> {
    data: Box<T>
}

§Description

Operation with Vec<_> is too bothered. For example, next code generates error.

#[macro_use]
extern crate peroxide;
use peroxide::prelude::*;

fn main() {
    let a = c!(1, 2, 3);
    assert_eq!(a * 2f64 - 1f64, c!(1, 3, 5));
}

Because we can’t implement Mul<Vec<f64>> for f64 and vice versa. Redox<T: Vector> makes the situation easy.

§Usage

  • ox(): Vector to Redox<T: Vector>
  • red(): Redox<T: Vector> to T (Ofcourse, T should be sized)
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = c!(1, 2, 3);
    assert_eq!((a.ox() * 2f64 - 1f64).red(), c!(1, 3, 5));
}

ox() and red() come from oxidation and reduction.

Structs§

Traits§