point_nd/
utils.rs

1
2#[cfg(any(feature = "appliers", feature = "var-dims"))]
3use arrayvec::ArrayVec;
4
5///
6/// Forces an ArrayVec to return it's contained array
7///
8/// For use ONLY within the apply, extend and contract methods as their constant
9/// generics ensure that ArrayVec's are always filled with initialised values
10///
11#[cfg(any(feature = "appliers", feature = "var-dims"))]
12pub(crate) fn arrvec_into_inner<T, const N: usize>(arrvec: ArrayVec<T, N>, method_name: &str) -> [T; N] {
13    match arrvec.into_inner() {
14        Ok(arr) => arr,
15        _ => panic!(
16            "Couldn't convert ArrayVec into array in {}() method. \
17             This operation should never have panicked. Please contact \
18             the maintainers of PointND if troubles persist",
19             method_name
20        )
21    }
22}
23
24#[cfg(any(feature = "appliers", feature = "var-dims"))]
25pub const ARRVEC_CAP: usize = u32::MAX as usize;
26
27/// Function pointer type to pass to  `apply()` in `PointND`'s
28#[cfg(feature = "appliers")]
29pub type ApplyFn<T, U> = fn(T) -> U;
30
31/// Function pointer type to pass to  `apply_dims()` in `PointND`'s
32#[cfg(feature = "appliers")]
33pub type ApplyDimsFn<T> = fn(T) -> T;
34
35///
36/// Function pointer type to pass to  `apply_vals()` in `PointND`'s
37///
38/// Is equivalent to the `ApplyPointFn` alias
39///
40#[cfg(feature = "appliers")]
41pub type ApplyValsFn<T, U, V>  = fn(T, V) -> U;
42
43///
44/// Function pointer type to pass to  `apply_point()` in `PointND`'s
45///
46/// Is equivalent to the `ApplyValsFn` alias
47///
48#[cfg(feature = "appliers")]
49pub type ApplyPointFn<T, U, V> = ApplyValsFn<T, U, V>;
50
51