generic_array/
impl_const_default.rs

1//! Const default implementation
2
3use crate::{ArrayLength, GenericArray, GenericArrayImplEven, GenericArrayImplOdd};
4use const_default::ConstDefault;
5
6impl<T, U: ConstDefault> ConstDefault for GenericArrayImplEven<T, U> {
7    const DEFAULT: Self = Self {
8        parents: [U::DEFAULT; 2],
9        _marker: core::marker::PhantomData,
10    };
11}
12
13impl<T: ConstDefault, U: ConstDefault> ConstDefault for GenericArrayImplOdd<T, U> {
14    const DEFAULT: Self = Self {
15        parents: [U::DEFAULT; 2],
16        data: T::DEFAULT,
17    };
18}
19
20impl<T, U: ArrayLength> ConstDefault for GenericArray<T, U>
21where
22    U::ArrayType<T>: ConstDefault,
23{
24    const DEFAULT: Self = Self {
25        data: ConstDefault::DEFAULT,
26    };
27}
28
29// `T: ConstDefault` is intentionally redundant to provide better hints in the docs
30impl<T: ConstDefault, U: ArrayLength> GenericArray<T, U>
31where
32    Self: ConstDefault,
33{
34    /// Returns the constant "default value" for an array using [ConstDefault]
35    #[inline(always)]
36    pub const fn const_default() -> Self {
37        Self::DEFAULT
38    }
39}