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.