wiwi::prelude_std

Trait Default

1.0.0 · Source
pub trait Default: Sized {
    // Required method
    fn default() -> Self;
}
Expand description

A trait for giving a type a useful default value.

Sometimes, you want to fall back to some kind of default value, and don’t particularly care what it is. This comes up often with structs that define a set of options:

struct SomeOptions {
    foo: i32,
    bar: f32,
}

How can we define some default values? You can use Default:

#[derive(Default)]
struct SomeOptions {
    foo: i32,
    bar: f32,
}

fn main() {
    let options: SomeOptions = Default::default();
}

Now, you get all of the default values. Rust implements Default for various primitives types.

If you want to override a particular option, but still retain the other defaults:

fn main() {
    let options = SomeOptions { foo: 42, ..Default::default() };
}

§Derivable

This trait can be used with #[derive] if all of the type’s fields implement Default. When derived, it will use the default value for each field’s type.

§enums

When using #[derive(Default)] on an enum, you need to choose which unit variant will be default. You do this by placing the #[default] attribute on the variant.

#[derive(Default)]
enum Kind {
    #[default]
    A,
    B,
    C,
}

You cannot use the #[default] attribute on non-unit or non-exhaustive variants.

The #[default] attribute was stabilized in Rust 1.62.0.

§How can I implement Default?

Provide an implementation for the default() method that returns the value of your type that should be the default:

enum Kind {
    A,
    B,
    C,
}

impl Default for Kind {
    fn default() -> Self { Kind::A }
}

§Examples

#[derive(Default)]
struct SomeOptions {
    foo: i32,
    bar: f32,
}

Required Methods§

1.0.0 · Source

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:

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:

enum Kind {
    A,
    B,
    C,
}

impl Default for Kind {
    fn default() -> Self { Kind::A }
}

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.

Implementors§

1.0.0 · Source§

impl Default for &str

1.10.0 · Source§

impl Default for &CStr

1.9.0 · Source§

impl Default for &OsStr

1.28.0 · Source§

impl Default for &mut str

1.0.0 · Source§

impl Default for AsciiChar

1.0.0 · Source§

impl Default for bool

1.0.0 · Source§

impl Default for char

1.0.0 · Source§

impl Default for f16

1.0.0 · Source§

impl Default for f32

1.0.0 · Source§

impl Default for f64

1.0.0 · Source§

impl Default for f128

1.0.0 · Source§

impl Default for i8

1.0.0 · Source§

impl Default for i16

1.0.0 · Source§

impl Default for i32

1.0.0 · Source§

impl Default for i64

1.0.0 · Source§

impl Default for i128

1.0.0 · Source§

impl Default for isize

1.0.0 · Source§

impl Default for u8

1.0.0 · Source§

impl Default for u16

1.0.0 · Source§

impl Default for u32

1.0.0 · Source§

impl Default for u64

1.0.0 · Source§

impl Default for u128

1.0.0 · Source§

impl Default for ()

1.0.0 · Source§

impl Default for usize

Source§

impl Default for wiwi::prelude_std::alloc_mod::Global

1.28.0 · Source§

impl Default for System

1.0.0 · Source§

impl Default for Error

1.13.0 · Source§

impl Default for DefaultHasher

1.7.0 · Source§

impl Default for wiwi::prelude_std::hash::RandomState

1.0.0 · Source§

impl Default for SipHasher

1.10.0 · Source§

impl Default for CString

1.3.0 · Source§

impl Default for Duration

1.9.0 · Source§

impl Default for OsString

1.75.0 · Source§

impl Default for FileTimes

1.0.0 · Source§

impl Default for std::io::util::Empty

1.0.0 · Source§

impl Default for Sink

1.17.0 · Source§

impl Default for PathBuf

1.75.0 · Source§

impl Default for ExitCode

The default value is ExitCode::SUCCESS

1.73.0 · Source§

impl Default for ExitStatus

The default value is one which indicates successful completion.

Source§

impl Default for DefaultRandomSource

1.10.0 · Source§

impl Default for std::sync::condvar::Condvar

Source§

impl Default for DateTime<FixedOffset>

Source§

impl Default for DateTime<Local>

Source§

impl Default for DateTime<Utc>

Source§

impl Default for Parsed

Source§

impl Default for NaiveDate

The default value for a NaiveDate is 1st of January 1970.

§Example

use chrono::NaiveDate;

let default_date = NaiveDate::default();
assert_eq!(default_date, NaiveDate::from_ymd_opt(1970, 1, 1).unwrap());
Source§

impl Default for NaiveDateTime

The default value for a NaiveDateTime is one with epoch 0 that is, 1st of January 1970 at 00:00:00.

§Example

use chrono::NaiveDateTime;

assert_eq!(NaiveDateTime::default(), NaiveDateTime::UNIX_EPOCH);
Source§

impl Default for NaiveTime

The default value for a NaiveTime is midnight, 00:00:00 exactly.

§Example

use chrono::NaiveTime;

let default_time = NaiveTime::default();
assert_eq!(default_time, NaiveTime::from_hms_opt(0, 0, 0).unwrap());
Source§

impl Default for TimeDelta

1.0.0 · Source§

impl Default for RangeFull

Source§

impl Default for Alignment

Returns Alignment::MIN, which is valid for any type.

1.80.0 · Source§

impl Default for Arc<str>

1.80.0 · Source§

impl Default for Arc<CStr>

1.0.0 · Source§

impl Default for AtomicBool

1.34.0 · Source§

impl Default for AtomicI8

1.34.0 · Source§

impl Default for AtomicI16

1.34.0 · Source§

impl Default for AtomicI32

1.34.0 · Source§

impl Default for AtomicI64

1.0.0 · Source§

impl Default for AtomicIsize

1.34.0 · Source§

impl Default for AtomicU8

1.34.0 · Source§

impl Default for AtomicU16

1.34.0 · Source§

impl Default for AtomicU32

1.34.0 · Source§

impl Default for AtomicU64

1.0.0 · Source§

impl Default for AtomicUsize

1.17.0 · Source§

impl Default for wiwi::prelude_std::Box<str>

1.17.0 · Source§

impl Default for wiwi::prelude_std::Box<CStr>

1.17.0 · Source§

impl Default for wiwi::prelude_std::Box<OsStr>

1.33.0 · Source§

impl Default for PhantomPinned

1.80.0 · Source§

impl Default for Rc<str>

1.80.0 · Source§

impl Default for Rc<CStr>

1.0.0 · Source§

impl Default for String

Source§

impl Default for StringInlineable

§

impl Default for Bytes

§

impl Default for BytesMut

§

impl Default for Condvar

§

impl Default for DirBuilder

§

impl Default for FixedState

§

impl Default for FixedState

§

impl Default for Global

§

impl Default for LocalSet

§

impl Default for MissedTickBehavior

§

impl Default for Notify

§

impl Default for Once

§

impl Default for OpenOptions

§

impl Default for OpenOptions

§

impl Default for RandomState

§

impl Default for RandomState

§

impl Default for SpinWait

§

impl Default for UnparkResult

1.70.0 · Source§

impl<'a, K, V> Default for alloc::collections::btree::map::Iter<'a, K, V>
where K: 'a, V: 'a,

1.70.0 · Source§

impl<'a, K, V> Default for alloc::collections::btree::map::IterMut<'a, K, V>
where K: 'a, V: 'a,

§

impl<A> Default for Box<str, A>
where A: Allocator + Default,

§

impl<A> Default for SmallVec<A>
where A: Array,

1.70.0 · Source§

impl<A, B> Default for Chain<A, B>
where A: Default, B: Default,

1.11.0 · Source§

impl<B> Default for Cow<'_, B>
where B: ToOwned + ?Sized, <B as ToOwned>::Owned: Default,

1.7.0 · Source§

impl<H> Default for BuildHasherDefault<H>

1.70.0 · Source§

impl<I> Default for Cloned<I>
where I: Default,

1.70.0 · Source§

impl<I> Default for Copied<I>
where I: Default,

1.70.0 · Source§

impl<I> Default for Enumerate<I>
where I: Default,

1.70.0 · Source§

impl<I> Default for Flatten<I>
where I: Default + Iterator, <I as Iterator>::Item: IntoIterator,

1.70.0 · Source§

impl<I> Default for Fuse<I>
where I: Default,

1.70.0 · Source§

impl<I> Default for Rev<I>
where I: Default,

Source§

impl<Idx> Default for core::range::Range<Idx>
where Idx: Default,

1.0.0 · Source§

impl<Idx> Default for wiwi::prelude_std::ops::Range<Idx>
where Idx: Default,

1.83.0 · Source§

impl<K> Default for std::collections::hash::set::IntoIter<K>

1.83.0 · Source§

impl<K> Default for std::collections::hash::set::Iter<'_, K>

§

impl<K> Default for Iter<'_, K>

§

impl<K, A> Default for IntoIter<K, A>
where A: Allocator,

1.0.0 · Source§

impl<K, V> Default for BTreeMap<K, V>

1.70.0 · Source§

impl<K, V> Default for alloc::collections::btree::map::Keys<'_, K, V>

1.70.0 · Source§

impl<K, V> Default for alloc::collections::btree::map::Range<'_, K, V>

1.82.0 · Source§

impl<K, V> Default for RangeMut<'_, K, V>

1.70.0 · Source§

impl<K, V> Default for alloc::collections::btree::map::Values<'_, K, V>

1.82.0 · Source§

impl<K, V> Default for alloc::collections::btree::map::ValuesMut<'_, K, V>

1.83.0 · Source§

impl<K, V> Default for std::collections::hash::map::IntoIter<K, V>

1.83.0 · Source§

impl<K, V> Default for std::collections::hash::map::IntoKeys<K, V>

1.83.0 · Source§

impl<K, V> Default for std::collections::hash::map::IntoValues<K, V>

1.83.0 · Source§

impl<K, V> Default for std::collections::hash::map::Iter<'_, K, V>

1.83.0 · Source§

impl<K, V> Default for std::collections::hash::map::IterMut<'_, K, V>

1.83.0 · Source§

impl<K, V> Default for std::collections::hash::map::Keys<'_, K, V>

1.83.0 · Source§

impl<K, V> Default for std::collections::hash::map::Values<'_, K, V>

1.83.0 · Source§

impl<K, V> Default for std::collections::hash::map::ValuesMut<'_, K, V>

§

impl<K, V> Default for Iter<'_, K, V>

§

impl<K, V> Default for IterMut<'_, K, V>

§

impl<K, V> Default for Keys<'_, K, V>

§

impl<K, V> Default for Values<'_, K, V>

§

impl<K, V> Default for ValuesMut<'_, K, V>

1.70.0 · Source§

impl<K, V, A> Default for alloc::collections::btree::map::IntoIter<K, V, A>
where A: Allocator + Default + Clone,

1.70.0 · Source§

impl<K, V, A> Default for alloc::collections::btree::map::IntoKeys<K, V, A>
where A: Allocator + Default + Clone,

1.70.0 · Source§

impl<K, V, A> Default for alloc::collections::btree::map::IntoValues<K, V, A>
where A: Allocator + Default + Clone,

§

impl<K, V, A> Default for IntoIter<K, V, A>
where A: Allocator,

§

impl<K, V, A> Default for IntoKeys<K, V, A>
where A: Allocator,

§

impl<K, V, A> Default for IntoValues<K, V, A>
where A: Allocator,

1.0.0 · Source§

impl<K, V, S> Default for std::collections::hash::map::HashMap<K, V, S>
where S: Default,

§

impl<K, V, S, A> Default for HashMap<K, V, S, A>
where S: Default, A: Default + Allocator,

§

impl<R, G, T> Default for ReentrantMutex<R, G, T>
where R: RawMutex, G: GetThreadId, T: Default + ?Sized,

§

impl<R, T> Default for Mutex<R, T>
where R: RawMutex, T: Default + ?Sized,

§

impl<R, T> Default for RwLock<R, T>
where R: RawRwLock, T: Default + ?Sized,

1.0.0 · Source§

impl<T> Default for &[T]

1.5.0 · Source§

impl<T> Default for &mut [T]

1.0.0 · Source§

impl<T> Default for Option<T>

1.4.0 · Source§

impl<T> Default for [T; 0]

1.4.0 · Source§

impl<T> Default for [T; 1]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 2]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 3]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 4]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 5]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 6]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 7]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 8]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 9]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 10]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 11]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 12]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 13]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 14]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 15]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 16]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 17]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 18]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 19]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 20]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 21]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 22]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 23]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 24]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 25]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 26]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 27]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 28]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 29]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 30]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 31]
where T: Default,

1.4.0 · Source§

impl<T> Default for [T; 32]
where T: Default,

1.0.0 · Source§

impl<T> Default for (T₁, T₂, …, Tₙ)
where T: Default,

This trait is implemented for tuples up to twelve items long.

Source§

impl<T> Default for VecChain<T>
where Vec<T>: Default,

1.0.0 · Source§

impl<T> Default for Cell<T>
where T: Default,

1.80.0 · Source§

impl<T> Default for LazyCell<T>
where T: Default,

1.70.0 · Source§

impl<T> Default for wiwi::prelude_std::cell::OnceCell<T>

1.0.0 · Source§

impl<T> Default for RefCell<T>
where T: Default,

Source§

impl<T> Default for SyncUnsafeCell<T>
where T: Default,

1.19.0 · Source§

impl<T> Default for Reverse<T>
where T: Default,

1.0.0 · Source§

impl<T> Default for BinaryHeap<T>
where T: Ord,

1.70.0 · Source§

impl<T> Default for alloc::collections::binary_heap::IntoIter<T>

1.82.0 · Source§

impl<T> Default for alloc::collections::binary_heap::Iter<'_, T>

1.0.0 · Source§

impl<T> Default for BTreeSet<T>

1.70.0 · Source§

impl<T> Default for alloc::collections::btree::set::Iter<'_, T>

1.70.0 · Source§

impl<T> Default for alloc::collections::btree::set::Range<'_, T>

1.70.0 · Source§

impl<T> Default for alloc::collections::linked_list::IntoIter<T>

1.70.0 · Source§

impl<T> Default for alloc::collections::linked_list::Iter<'_, T>

1.70.0 · Source§

impl<T> Default for alloc::collections::linked_list::IterMut<'_, T>

1.0.0 · Source§

impl<T> Default for LinkedList<T>

1.82.0 · Source§

impl<T> Default for alloc::collections::vec_deque::iter::Iter<'_, T>

1.82.0 · Source§

impl<T> Default for alloc::collections::vec_deque::iter_mut::IterMut<'_, T>

1.0.0 · Source§

impl<T> Default for VecDeque<T>

1.74.0 · Source§

impl<T> Default for Saturating<T>
where T: Default,

1.0.0 · Source§

impl<T> Default for Wrapping<T>
where T: Default,

Source§

impl<T> Default for Exclusive<T>
where T: Default + ?Sized,

1.0.0 · Source§

impl<T> Default for Cursor<T>
where T: Default,

1.80.0 · Source§

impl<T> Default for LazyLock<T>
where T: Default,

1.10.0 · Source§

impl<T> Default for std::sync::mutex::Mutex<T>
where T: Default + ?Sized,

1.70.0 · Source§

impl<T> Default for OnceLock<T>

Source§

impl<T> Default for ReentrantLock<T>
where T: Default,

1.10.0 · Source§

impl<T> Default for std::sync::rwlock::RwLock<T>
where T: Default,

1.2.0 · Source§

impl<T> Default for wiwi::prelude_std::iter::Empty<T>

1.62.0 · Source§

impl<T> Default for AssertUnwindSafe<T>
where T: Default,

1.70.0 · Source§

impl<T> Default for wiwi::prelude_std::slice::Iter<'_, T>

1.70.0 · Source§

impl<T> Default for wiwi::prelude_std::slice::IterMut<'_, T>

1.80.0 · Source§

impl<T> Default for Arc<[T]>

1.0.0 · Source§

impl<T> Default for Arc<T>
where T: Default,

1.10.0 · Source§

impl<T> Default for wiwi::prelude_std::ArcWeak<T>

1.0.0 · Source§

impl<T> Default for AtomicPtr<T>

1.0.0 · Source§

impl<T> Default for wiwi::prelude_std::Box<[T]>

1.0.0 · Source§

impl<T> Default for wiwi::prelude_std::Box<T>
where T: Default,

1.20.0 · Source§

impl<T> Default for ManuallyDrop<T>
where T: Default + ?Sized,

1.0.0 · Source§

impl<T> Default for PhantomData<T>
where T: ?Sized,

1.80.0 · Source§

impl<T> Default for Rc<[T]>

1.0.0 · Source§

impl<T> Default for Rc<T>
where T: Default,

1.10.0 · Source§

impl<T> Default for wiwi::prelude_std::RcWeak<T>

1.10.0 · Source§

impl<T> Default for UnsafeCell<T>
where T: Default,

1.0.0 · Source§

impl<T> Default for wiwi::prelude_std::Vec<T>

§

impl<T> Default for Box<T>
where T: Default,

§

impl<T> Default for Iter<'_, T>

§

impl<T> Default for IterHash<'_, T>

§

impl<T> Default for IterHashMut<'_, T>

§

impl<T> Default for IterMut<'_, T>

§

impl<T> Default for JoinSet<T>

§

impl<T> Default for Mutex<T>
where T: Default,

§

impl<T> Default for OnceCell<T>

§

impl<T> Default for RwLock<T>
where T: Default + ?Sized,

§

impl<T> Default for Sender<T>
where T: Default,

§

impl<T> Default for Vec<T>

1.70.0 · Source§

impl<T, A> Default for alloc::collections::btree::set::IntoIter<T, A>
where A: Allocator + Default + Clone,

1.70.0 · Source§

impl<T, A> Default for wiwi::prelude_std::vec::IntoIter<T, A>
where A: Allocator + Default,

§

impl<T, A> Default for Box<[T], A>
where A: Allocator + Default,

§

impl<T, A> Default for HashTable<T, A>
where A: Allocator + Default,

§

impl<T, A> Default for IntoIter<T, A>
where A: Allocator,

Source§

impl<T, M> Default for Nominal<T, M>
where T: Default,

1.0.0 · Source§

impl<T, S> Default for std::collections::hash::set::HashSet<T, S>
where S: Default,

§

impl<T, S, A> Default for HashSet<T, S, A>
where S: Default, A: Default + Allocator,

Source§

impl<T, const N: usize> Default for ArrayChain<T, N>
where [T; N]: Default,

Source§

impl<T, const N: usize> Default for Mask<T, N>

Source§

impl<T, const N: usize> Default for Simd<T, N>