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§
type Output: ExactSizeIterator<Item = T>
Required Methods§
Sourcefn linspace(&self, count: usize) -> Self::Output
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]);Sourcefn linspace_slice(&self, slice: &mut [T])
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]);Sourceunsafe fn linspace_uninit_slice<'a>(
&self,
slice: &'a mut [MaybeUninit<T>],
) -> &'a mut [T]
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§
Sourcefn linspace_array<const N: usize>(&self) -> [T; N]
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.