pub trait ConstDefault: Sized {
const DEFAULT: Self;
}
Expand description
Implements a compilation time default value for the implemented type.
§Note
Unlike the Default
trait implementation the DEFAULT
of implementations
of this trait can be used in constant evaluation contexts.
§Example
const VEC: Vec<u8> = <Vec<u8> as ConstDefault>::DEFAULT;
The above code works while the below code does not:
ⓘ
const VEC: Vec<u8> = <Vec<u8> as Default>::default();
Required Associated Constants§
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 ConstDefault for String
Available on crate features std
or alloc
only.
impl ConstDefault for String
Available on crate features
std
or alloc
only.Source§impl ConstDefault for PhantomPinned
impl ConstDefault for PhantomPinned
Source§impl ConstDefault for AtomicBool
Available on crate features default
or enable-atomics
only.
impl ConstDefault for AtomicBool
Available on crate features
default
or enable-atomics
only.Source§impl ConstDefault for AtomicI8
Available on crate features default
or enable-atomics
only.
impl ConstDefault for AtomicI8
Available on crate features
default
or enable-atomics
only.Source§impl ConstDefault for AtomicI16
Available on crate features default
or enable-atomics
only.
impl ConstDefault for AtomicI16
Available on crate features
default
or enable-atomics
only.Source§impl ConstDefault for AtomicI32
Available on crate features default
or enable-atomics
only.
impl ConstDefault for AtomicI32
Available on crate features
default
or enable-atomics
only.Source§impl ConstDefault for AtomicI64
Available on crate features default
or enable-atomics
only.
impl ConstDefault for AtomicI64
Available on crate features
default
or enable-atomics
only.Source§impl ConstDefault for AtomicIsize
Available on crate features default
or enable-atomics
only.
impl ConstDefault for AtomicIsize
Available on crate features
default
or enable-atomics
only.Source§impl ConstDefault for AtomicU8
Available on crate features default
or enable-atomics
only.
impl ConstDefault for AtomicU8
Available on crate features
default
or enable-atomics
only.Source§impl ConstDefault for AtomicU16
Available on crate features default
or enable-atomics
only.
impl ConstDefault for AtomicU16
Available on crate features
default
or enable-atomics
only.Source§impl ConstDefault for AtomicU32
Available on crate features default
or enable-atomics
only.
impl ConstDefault for AtomicU32
Available on crate features
default
or enable-atomics
only.Source§impl ConstDefault for AtomicU64
Available on crate features default
or enable-atomics
only.
impl ConstDefault for AtomicU64
Available on crate features
default
or enable-atomics
only.Source§impl ConstDefault for AtomicUsize
Available on crate features default
or enable-atomics
only.
impl ConstDefault for AtomicUsize
Available on crate features
default
or enable-atomics
only.Source§impl<'a, T> ConstDefault for Cow<'a, T>
Available on crate features std
or alloc
only.
impl<'a, T> ConstDefault for Cow<'a, T>
Available on crate features
std
or alloc
only.Source§impl<A: ConstDefault, B: ConstDefault, C: ConstDefault, D: ConstDefault, E: ConstDefault, F: ConstDefault, G: ConstDefault, H: ConstDefault, I: ConstDefault, J: ConstDefault, K: ConstDefault, L: ConstDefault> ConstDefault for (A, B, C, D, E, F, G, H, I, J, K, L)
impl<A: ConstDefault, B: ConstDefault, C: ConstDefault, D: ConstDefault, E: ConstDefault, F: ConstDefault, G: ConstDefault, H: ConstDefault, I: ConstDefault, J: ConstDefault, K: ConstDefault, L: ConstDefault> ConstDefault for (A, B, C, D, E, F, G, H, I, J, K, L)
Source§impl<B: ConstDefault, C: ConstDefault, D: ConstDefault, E: ConstDefault, F: ConstDefault, G: ConstDefault, H: ConstDefault, I: ConstDefault, J: ConstDefault, K: ConstDefault, L: ConstDefault> ConstDefault for (B, C, D, E, F, G, H, I, J, K, L)
impl<B: ConstDefault, C: ConstDefault, D: ConstDefault, E: ConstDefault, F: ConstDefault, G: ConstDefault, H: ConstDefault, I: ConstDefault, J: ConstDefault, K: ConstDefault, L: ConstDefault> ConstDefault for (B, C, D, E, F, G, H, I, J, K, L)
Source§impl<C: ConstDefault, D: ConstDefault, E: ConstDefault, F: ConstDefault, G: ConstDefault, H: ConstDefault, I: ConstDefault, J: ConstDefault, K: ConstDefault, L: ConstDefault> ConstDefault for (C, D, E, F, G, H, I, J, K, L)
impl<C: ConstDefault, D: ConstDefault, E: ConstDefault, F: ConstDefault, G: ConstDefault, H: ConstDefault, I: ConstDefault, J: ConstDefault, K: ConstDefault, L: ConstDefault> ConstDefault for (C, D, E, F, G, H, I, J, K, L)
Source§impl<D: ConstDefault, E: ConstDefault, F: ConstDefault, G: ConstDefault, H: ConstDefault, I: ConstDefault, J: ConstDefault, K: ConstDefault, L: ConstDefault> ConstDefault for (D, E, F, G, H, I, J, K, L)
impl<D: ConstDefault, E: ConstDefault, F: ConstDefault, G: ConstDefault, H: ConstDefault, I: ConstDefault, J: ConstDefault, K: ConstDefault, L: ConstDefault> ConstDefault for (D, E, F, G, H, I, J, K, L)
Source§impl<E: ConstDefault, F: ConstDefault, G: ConstDefault, H: ConstDefault, I: ConstDefault, J: ConstDefault, K: ConstDefault, L: ConstDefault> ConstDefault for (E, F, G, H, I, J, K, L)
impl<E: ConstDefault, F: ConstDefault, G: ConstDefault, H: ConstDefault, I: ConstDefault, J: ConstDefault, K: ConstDefault, L: ConstDefault> ConstDefault for (E, F, G, H, I, J, K, L)
Source§impl<F: ConstDefault, G: ConstDefault, H: ConstDefault, I: ConstDefault, J: ConstDefault, K: ConstDefault, L: ConstDefault> ConstDefault for (F, G, H, I, J, K, L)
impl<F: ConstDefault, G: ConstDefault, H: ConstDefault, I: ConstDefault, J: ConstDefault, K: ConstDefault, L: ConstDefault> ConstDefault for (F, G, H, I, J, K, L)
Source§impl<G: ConstDefault, H: ConstDefault, I: ConstDefault, J: ConstDefault, K: ConstDefault, L: ConstDefault> ConstDefault for (G, H, I, J, K, L)
impl<G: ConstDefault, H: ConstDefault, I: ConstDefault, J: ConstDefault, K: ConstDefault, L: ConstDefault> ConstDefault for (G, H, I, J, K, L)
Source§impl<H: ConstDefault, I: ConstDefault, J: ConstDefault, K: ConstDefault, L: ConstDefault> ConstDefault for (H, I, J, K, L)
impl<H: ConstDefault, I: ConstDefault, J: ConstDefault, K: ConstDefault, L: ConstDefault> ConstDefault for (H, I, J, K, L)
Source§impl<I: ConstDefault, J: ConstDefault, K: ConstDefault, L: ConstDefault> ConstDefault for (I, J, K, L)
impl<I: ConstDefault, J: ConstDefault, K: ConstDefault, L: ConstDefault> ConstDefault for (I, J, K, L)
Source§impl<J: ConstDefault, K: ConstDefault, L: ConstDefault> ConstDefault for (J, K, L)
impl<J: ConstDefault, K: ConstDefault, L: ConstDefault> ConstDefault for (J, K, L)
Source§impl<K: Ord, V> ConstDefault for BTreeMap<K, V>
Available on (crate features std
or alloc
) and crate feature unstable
only.
impl<K: Ord, V> ConstDefault for BTreeMap<K, V>
Available on (crate features
std
or alloc
) and crate feature unstable
only.Source§impl<K: ConstDefault, L: ConstDefault> ConstDefault for (K, L)
impl<K: ConstDefault, L: ConstDefault> ConstDefault for (K, L)
Source§impl<L: ConstDefault> ConstDefault for (L,)
impl<L: ConstDefault> ConstDefault for (L,)
Source§impl<T> ConstDefault for LinkedList<T>
Available on crate features std
or alloc
only.
impl<T> ConstDefault for LinkedList<T>
Available on crate features
std
or alloc
only.Source§impl<T> ConstDefault for Vec<T>
Available on crate features std
or alloc
only.
impl<T> ConstDefault for Vec<T>
Available on crate features
std
or alloc
only.Source§impl<T> ConstDefault for AtomicPtr<T>
Available on crate features default
or enable-atomics
only.
impl<T> ConstDefault for AtomicPtr<T>
Available on crate features
default
or enable-atomics
only.Source§impl<T: Ord> ConstDefault for BTreeSet<T>
Available on (crate features std
or alloc
) and crate feature unstable
only.
impl<T: Ord> ConstDefault for BTreeSet<T>
Available on (crate features
std
or alloc
) and crate feature unstable
only.