Trait core::default::Default
[−]
[src]
pub trait Default: Sized { fn default() -> Self; }
A trait for giving a type a useful default value.
A struct can derive default implementations of Default
for basic types using
#[derive(Default)]
.
Examples
fn main() { #[allow(dead_code)] #[derive(Default)] struct SomeOptions { foo: i32, bar: f32, } }#[derive(Default)] struct SomeOptions { foo: i32, bar: f32, }
Required Methods
fn default() -> Self
Returns the "default value" for a type.
Default values are often some kind of initial value, identity value, or anything else that may make sense as a default.
Examples
Using built-in default values:
fn main() { let i: i8 = Default::default(); let (x, y): (Option<String>, f64) = Default::default(); let (a, b, (c, d)): (i32, u32, (bool, bool)) = Default::default(); }let i: i8 = Default::default(); let (x, y): (Option<String>, f64) = Default::default(); let (a, b, (c, d)): (i32, u32, (bool, bool)) = Default::default();
Making your own:
fn main() { #[allow(dead_code)] enum Kind { A, B, C, } impl Default for Kind { fn default() -> Kind { Kind::A } } }enum Kind { A, B, C, } impl Default for Kind { fn default() -> Kind { Kind::A } }
Implementors
impl<T: Default> Default for Wrapping<T>
impl<T: ?Sized> Default for PhantomData<T>
impl Default for ()
impl Default for bool
impl Default for char
impl Default for usize
impl Default for u8
impl Default for u16
impl Default for u32
impl Default for u64
impl Default for isize
impl Default for i8
impl Default for i16
impl Default for i32
impl Default for i64
impl Default for f32
impl Default for f64
impl<T> Default for [T; 32] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1] where T: Default
impl<T> Default for [T; $n - 1]
impl Default for AtomicBool
impl Default for AtomicIsize
impl Default for AtomicUsize
impl<T> Default for AtomicPtr<T>
impl<T: Default + Copy> Default for Cell<T>
impl<T: Default> Default for RefCell<T>
impl<T> Default for Empty<T>
impl<T> Default for Option<T>
impl<'a, T> Default for &'a [T]
impl<'a, T> Default for &'a mut [T]
impl<'a> Default for &'a str
impl Default for SipHasher
impl<H> Default for BuildHasherDefault<H>
impl<A: Default> Default for (A,)
impl<A: Default, B: Default> Default for (A, B)
impl<A: Default, B: Default, C: Default> Default for (A, B, C)
impl<A: Default, B: Default, C: Default, D: Default> Default for (A, B, C, D)
impl<A: Default, B: Default, C: Default, D: Default, E: Default> Default for (A, B, C, D, E)
impl<A: Default, B: Default, C: Default, D: Default, E: Default, F: Default> Default for (A, B, C, D, E, F)
impl<A: Default, B: Default, C: Default, D: Default, E: Default, F: Default, G: Default> Default for (A, B, C, D, E, F, G)
impl<A: Default, B: Default, C: Default, D: Default, E: Default, F: Default, G: Default, H: Default> Default for (A, B, C, D, E, F, G, H)
impl<A: Default, B: Default, C: Default, D: Default, E: Default, F: Default, G: Default, H: Default, I: Default> Default for (A, B, C, D, E, F, G, H, I)
impl<A: Default, B: Default, C: Default, D: Default, E: Default, F: Default, G: Default, H: Default, I: Default, J: Default> Default for (A, B, C, D, E, F, G, H, I, J)
impl<A: Default, B: Default, C: Default, D: Default, E: Default, F: Default, G: Default, H: Default, I: Default, J: Default, K: Default> Default for (A, B, C, D, E, F, G, H, I, J, K)
impl<A: Default, B: Default, C: Default, D: Default, E: Default, F: Default, G: Default, H: Default, I: Default, J: Default, K: Default, L: Default> Default for (A, B, C, D, E, F, G, H, I, J, K, L)