Linspace

Trait Linspace 

Source
pub trait Linspace<T>: Sized {
    type Output: ExactSizeIterator<Item = T>;

    // Required methods
    fn linspace(&self, count: usize) -> Self::Output;
    fn linspace_slice(&self, slice: &mut [T]);
    unsafe fn linspace_uninit_slice<'a>(
        &self,
        slice: &'a mut [MaybeUninit<T>],
    ) -> &'a mut [T];

    // Provided method
    fn linspace_array<const N: usize>(&self) -> [T; N] { ... }
}

Required Associated Types§

Required Methods§

Source

fn linspace(&self, count: usize) -> Self::Output

Returns an iterator of evenly spaced values. count must be specified.

§Example
use linspace::*;
 
let x: Vec<u32> = (0..100).linspace(4).collect();
assert_eq!(x, [0, 25, 50, 75]);
 
let x: Vec<u32> = (0..=100).linspace(5).collect();
assert_eq!(x, [0, 25, 50, 75, 100]);
Source

fn linspace_slice(&self, slice: &mut [T])

Fills a slice with evenly spaced values.

§Example
use linspace::*;
 
let mut x = [0, 0, 0, 0, 0];
 
(0..=100).linspace_slice(&mut x);
assert_eq!(x, [0, 25, 50, 75, 100]);
Source

unsafe fn linspace_uninit_slice<'a>( &self, slice: &'a mut [MaybeUninit<T>], ) -> &'a mut [T]

Fills a slice with evenly spaced values.

§Safety

Values in the slice will be overwritten. They will not be dropped.

If T is not trivially droppable, the slice must be uninitialized.

§Example
use core::mem::MaybeUninit;
 
use linspace::*;
 
let mut x = [const {MaybeUninit::uninit()}; 5];
 
let x = unsafe {
    (0..=100).linspace_uninit_slice(&mut x)
};
assert_eq!(x, [0, 25, 50, 75, 100]);

Provided Methods§

Source

fn linspace_array<const N: usize>(&self) -> [T; N]

Returns an array of evenly spaced values.

§Example
use linspace::*;
 
let x: [u32; 4] = (0..100).linspace_array();
assert_eq!(x, [0, 25, 50, 75]);
 
let x: [u32; 5] = (0..=100).linspace_array();
assert_eq!(x, [0, 25, 50, 75, 100]);

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<T> Linspace<T> for Range<T>
where T: Copy + Add<Output = T> + NumScale<f64>, Linspaced<T, false>: ExactSizeIterator<Item = T>,

Source§

type Output = Linspaced<T, false>

Source§

fn linspace(&self, count: usize) -> Self::Output

Source§

unsafe fn linspace_uninit_slice<'a>( &self, slice: &'a mut [MaybeUninit<T>], ) -> &'a mut [T]

Source§

fn linspace_slice(&self, slice: &mut [T])

Source§

impl<T> Linspace<T> for RangeInclusive<T>
where T: Copy + Add<Output = T> + NumScale<f64>, Linspaced<T, true>: ExactSizeIterator<Item = T>,

Source§

type Output = Linspaced<T, true>

Source§

fn linspace(&self, count: usize) -> Self::Output

Source§

unsafe fn linspace_uninit_slice<'a>( &self, slice: &'a mut [MaybeUninit<T>], ) -> &'a mut [T]

Source§

fn linspace_slice(&self, slice: &mut [T])

Implementors§