Trait core_extensions::ConstDefault
source · [−]Available on crate feature
const_default
only.Expand description
A const equivalent of the Default
trait.
This trait can be derived with the ConstDefault
derive macro
(requires the “derive” feature).
Features
Enabling the “rust_1_51” feature allows arrays of all lengths to implement this trait, otherwise it’s only implemented for arrays up to 32 elements long.
Example
Manually implementing ConstDefault
for a struct
use core_extensions::{ConstDefault, const_default};
#[derive(Debug,PartialEq)]
struct Point<T>{
x: T,
y: T,
}
impl<T> ConstDefault for Point<T>
where
T: ConstDefault
{
const DEFAULT: Self = Point {
// `const_default!()` is equivalent to `ConstDefault::DEFAULT`
x: const_default!(),
y: const_default!(),
};
}
assert_eq!(const_default!(Point<u8>), Point{x: 0, y: 0});
assert_eq!(const_default!(Point<f32>), Point{x: 0.0, y: 0.0});
assert_eq!(const_default!(Point<Option<()>>), Point{x: None, y: None});
Required Associated Constants
Implementations on Foreign Types
sourceimpl<T: ConstDefault, const N: usize> ConstDefault for [T; N]
Available on crate feature const_params
only.
impl<T: ConstDefault, const N: usize> ConstDefault for [T; N]
Available on crate feature
const_params
only.When the “const_params” feature is disabled, the ConstDefault trait is implemented for arrays up to 32 elements long.
sourceimpl ConstDefault for ()
impl ConstDefault for ()
sourceimpl<A> ConstDefault for (A,) where
A: ConstDefault + Sized,
impl<A> ConstDefault for (A,) where
A: ConstDefault + Sized,
sourceimpl<A, B> ConstDefault for (A, B) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
impl<A, B> ConstDefault for (A, B) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
sourceimpl<A, B, C> ConstDefault for (A, B, C) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
impl<A, B, C> ConstDefault for (A, B, C) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
sourceimpl<A, B, C, D> ConstDefault for (A, B, C, D) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
impl<A, B, C, D> ConstDefault for (A, B, C, D) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
sourceimpl<A, B, C, D, E> ConstDefault for (A, B, C, D, E) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
impl<A, B, C, D, E> ConstDefault for (A, B, C, D, E) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
sourceimpl<A, B, C, D, E, F> ConstDefault for (A, B, C, D, E, F) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
impl<A, B, C, D, E, F> ConstDefault for (A, B, C, D, E, F) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
sourceimpl<A, B, C, D, E, F, G> ConstDefault for (A, B, C, D, E, F, G) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
G: ConstDefault + Sized,
impl<A, B, C, D, E, F, G> ConstDefault for (A, B, C, D, E, F, G) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
G: ConstDefault + Sized,
sourceimpl<A, B, C, D, E, F, G, H> ConstDefault for (A, B, C, D, E, F, G, H) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
G: ConstDefault + Sized,
H: ConstDefault + Sized,
impl<A, B, C, D, E, F, G, H> ConstDefault for (A, B, C, D, E, F, G, H) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
G: ConstDefault + Sized,
H: ConstDefault + Sized,
sourceimpl<A, B, C, D, E, F, G, H, I> ConstDefault for (A, B, C, D, E, F, G, H, I) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
G: ConstDefault + Sized,
H: ConstDefault + Sized,
I: ConstDefault + Sized,
impl<A, B, C, D, E, F, G, H, I> ConstDefault for (A, B, C, D, E, F, G, H, I) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
G: ConstDefault + Sized,
H: ConstDefault + Sized,
I: ConstDefault + Sized,
sourceimpl<A, B, C, D, E, F, G, H, I, J> ConstDefault for (A, B, C, D, E, F, G, H, I, J) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
G: ConstDefault + Sized,
H: ConstDefault + Sized,
I: ConstDefault + Sized,
J: ConstDefault + Sized,
impl<A, B, C, D, E, F, G, H, I, J> ConstDefault for (A, B, C, D, E, F, G, H, I, J) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
G: ConstDefault + Sized,
H: ConstDefault + Sized,
I: ConstDefault + Sized,
J: ConstDefault + Sized,
sourceimpl<A, B, C, D, E, F, G, H, I, J, K> ConstDefault for (A, B, C, D, E, F, G, H, I, J, K) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
G: ConstDefault + Sized,
H: ConstDefault + Sized,
I: ConstDefault + Sized,
J: ConstDefault + Sized,
K: ConstDefault + Sized,
impl<A, B, C, D, E, F, G, H, I, J, K> ConstDefault for (A, B, C, D, E, F, G, H, I, J, K) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
G: ConstDefault + Sized,
H: ConstDefault + Sized,
I: ConstDefault + Sized,
J: ConstDefault + Sized,
K: ConstDefault + Sized,
sourceimpl<A, B, C, D, E, F, G, H, I, J, K, L> ConstDefault for (A, B, C, D, E, F, G, H, I, J, K, L) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
G: ConstDefault + Sized,
H: ConstDefault + Sized,
I: ConstDefault + Sized,
J: ConstDefault + Sized,
K: ConstDefault + Sized,
L: ConstDefault + Sized,
impl<A, B, C, D, E, F, G, H, I, J, K, L> ConstDefault for (A, B, C, D, E, F, G, H, I, J, K, L) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
G: ConstDefault + Sized,
H: ConstDefault + Sized,
I: ConstDefault + Sized,
J: ConstDefault + Sized,
K: ConstDefault + Sized,
L: ConstDefault + Sized,
sourceimpl<A, B, C, D, E, F, G, H, I, J, K, L, M> ConstDefault for (A, B, C, D, E, F, G, H, I, J, K, L, M) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
G: ConstDefault + Sized,
H: ConstDefault + Sized,
I: ConstDefault + Sized,
J: ConstDefault + Sized,
K: ConstDefault + Sized,
L: ConstDefault + Sized,
M: ConstDefault + Sized,
impl<A, B, C, D, E, F, G, H, I, J, K, L, M> ConstDefault for (A, B, C, D, E, F, G, H, I, J, K, L, M) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
G: ConstDefault + Sized,
H: ConstDefault + Sized,
I: ConstDefault + Sized,
J: ConstDefault + Sized,
K: ConstDefault + Sized,
L: ConstDefault + Sized,
M: ConstDefault + Sized,
sourceimpl<A, B, C, D, E, F, G, H, I, J, K, L, M, N> ConstDefault for (A, B, C, D, E, F, G, H, I, J, K, L, M, N) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
G: ConstDefault + Sized,
H: ConstDefault + Sized,
I: ConstDefault + Sized,
J: ConstDefault + Sized,
K: ConstDefault + Sized,
L: ConstDefault + Sized,
M: ConstDefault + Sized,
N: ConstDefault + Sized,
impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N> ConstDefault for (A, B, C, D, E, F, G, H, I, J, K, L, M, N) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
G: ConstDefault + Sized,
H: ConstDefault + Sized,
I: ConstDefault + Sized,
J: ConstDefault + Sized,
K: ConstDefault + Sized,
L: ConstDefault + Sized,
M: ConstDefault + Sized,
N: ConstDefault + Sized,
sourceimpl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O> ConstDefault for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
G: ConstDefault + Sized,
H: ConstDefault + Sized,
I: ConstDefault + Sized,
J: ConstDefault + Sized,
K: ConstDefault + Sized,
L: ConstDefault + Sized,
M: ConstDefault + Sized,
N: ConstDefault + Sized,
O: ConstDefault + Sized,
impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O> ConstDefault for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
G: ConstDefault + Sized,
H: ConstDefault + Sized,
I: ConstDefault + Sized,
J: ConstDefault + Sized,
K: ConstDefault + Sized,
L: ConstDefault + Sized,
M: ConstDefault + Sized,
N: ConstDefault + Sized,
O: ConstDefault + Sized,
sourceimpl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> ConstDefault for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
G: ConstDefault + Sized,
H: ConstDefault + Sized,
I: ConstDefault + Sized,
J: ConstDefault + Sized,
K: ConstDefault + Sized,
L: ConstDefault + Sized,
M: ConstDefault + Sized,
N: ConstDefault + Sized,
O: ConstDefault + Sized,
P: ConstDefault + Sized,
impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> ConstDefault for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) where
A: ConstDefault + Sized,
B: ConstDefault + Sized,
C: ConstDefault + Sized,
D: ConstDefault + Sized,
E: ConstDefault + Sized,
F: ConstDefault + Sized,
G: ConstDefault + Sized,
H: ConstDefault + Sized,
I: ConstDefault + Sized,
J: ConstDefault + Sized,
K: ConstDefault + Sized,
L: ConstDefault + Sized,
M: ConstDefault + Sized,
N: ConstDefault + Sized,
O: ConstDefault + Sized,
P: ConstDefault + Sized,
sourceimpl ConstDefault for isize
impl ConstDefault for isize
sourceimpl ConstDefault for usize
impl ConstDefault for usize
sourceimpl ConstDefault for i8
impl ConstDefault for i8
sourceimpl ConstDefault for u8
impl ConstDefault for u8
sourceimpl ConstDefault for i16
impl ConstDefault for i16
sourceimpl ConstDefault for u16
impl ConstDefault for u16
sourceimpl ConstDefault for i32
impl ConstDefault for i32
sourceimpl ConstDefault for u32
impl ConstDefault for u32
sourceimpl ConstDefault for i64
impl ConstDefault for i64
sourceimpl ConstDefault for u64
impl ConstDefault for u64
sourceimpl ConstDefault for f32
impl ConstDefault for f32
sourceimpl ConstDefault for f64
impl ConstDefault for f64
sourceimpl ConstDefault for bool
impl ConstDefault for bool
sourceimpl ConstDefault for char
impl ConstDefault for char
sourceimpl<T: ?Sized> ConstDefault for PhantomData<T>
impl<T: ?Sized> ConstDefault for PhantomData<T>
sourceimpl<T> ConstDefault for Option<T>
impl<T> ConstDefault for Option<T>
sourceimpl<'a> ConstDefault for &'a str
impl<'a> ConstDefault for &'a str
sourceimpl<'a, T: 'a> ConstDefault for &'a [T]
impl<'a, T: 'a> ConstDefault for &'a [T]
sourceimpl<T: ConstDefault> ConstDefault for Wrapping<T>
impl<T: ConstDefault> ConstDefault for Wrapping<T>
sourceimpl<T: ConstDefault> ConstDefault for Reverse<T>
impl<T: ConstDefault> ConstDefault for Reverse<T>
sourceimpl<T> ConstDefault for Empty<T>
impl<T> ConstDefault for Empty<T>
sourceimpl ConstDefault for AtomicUsize
impl ConstDefault for AtomicUsize
sourceimpl ConstDefault for AtomicIsize
impl ConstDefault for AtomicIsize
sourceimpl ConstDefault for AtomicBool
impl ConstDefault for AtomicBool
sourceimpl<T: ConstDefault> ConstDefault for Cell<T>
impl<T: ConstDefault> ConstDefault for Cell<T>
sourceimpl<T: ConstDefault> ConstDefault for RefCell<T>
impl<T: ConstDefault> ConstDefault for RefCell<T>
sourceimpl<T: ConstDefault> ConstDefault for UnsafeCell<T>
impl<T: ConstDefault> ConstDefault for UnsafeCell<T>
sourceimpl ConstDefault for Duration
impl ConstDefault for Duration
sourceimpl ConstDefault for i128
impl ConstDefault for i128
sourceimpl ConstDefault for u128
impl ConstDefault for u128
sourceimpl<T: ConstDefault> ConstDefault for ManuallyDrop<T>
impl<T: ConstDefault> ConstDefault for ManuallyDrop<T>
sourceimpl ConstDefault for AtomicI8
impl ConstDefault for AtomicI8
sourceimpl ConstDefault for AtomicU8
impl ConstDefault for AtomicU8
sourceimpl ConstDefault for AtomicI16
impl ConstDefault for AtomicI16
sourceimpl ConstDefault for AtomicU16
impl ConstDefault for AtomicU16
sourceimpl ConstDefault for AtomicI32
impl ConstDefault for AtomicI32
sourceimpl ConstDefault for AtomicU32
impl ConstDefault for AtomicU32
sourceimpl ConstDefault for AtomicI64
impl ConstDefault for AtomicI64
sourceimpl ConstDefault for AtomicU64
impl ConstDefault for AtomicU64
sourceimpl<T> ConstDefault for Vec<T>
Available on crate feature alloc
only.
impl<T> ConstDefault for Vec<T>
Available on crate feature
alloc
only.sourceimpl ConstDefault for String
Available on crate feature alloc
only.
impl ConstDefault for String
Available on crate feature
alloc
only.sourceimpl<T> ConstDefault for LinkedList<T>
Available on crate feature alloc
only.
impl<T> ConstDefault for LinkedList<T>
Available on crate feature
alloc
only.sourceimpl<'a, B: ?Sized + ToOwned + 'a> ConstDefault for Cow<'a, B> where
B::Owned: ConstDefault + 'a,
Available on crate feature alloc
only.
impl<'a, B: ?Sized + ToOwned + 'a> ConstDefault for Cow<'a, B> where
B::Owned: ConstDefault + 'a,
Available on crate feature
alloc
only.Implementors
sourceimpl ConstDefault for False
Available on crate feature type_level_bool
only.
impl ConstDefault for False
Available on crate feature
type_level_bool
only.sourceimpl ConstDefault for True
Available on crate feature type_level_bool
only.
impl ConstDefault for True
Available on crate feature
type_level_bool
only.