Trait otter_api_tests::imports::failure::_core::default::Default 1.0.0[−][src]
pub trait Default { 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 struct
s
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 derive
d, it will use the default value for each field’s type.
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
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 } }
Implementations on Foreign Types
pub fn default() -> Box<OsStr, Global>ⓘNotable traits for Box<R, Global>
impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
A: Allocator,
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
A: Allocator + 'static,
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
[src]pub fn default() -> Box<CStr, Global>ⓘNotable traits for Box<R, Global>
impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
A: Allocator,
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
A: Allocator + 'static,
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
[src]Creates an empty LinkedList<T>
.
pub fn default() -> Box<T, Global>ⓘNotable traits for Box<R, Global>
impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
A: Allocator,
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
A: Allocator + 'static,
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
[src]
pub fn default() -> Box<T, Global>ⓘNotable traits for Box<R, Global>
impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
A: Allocator,
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
A: Allocator + 'static,
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
[src]Creates a Box<T>
, with the Default
value for T.
pub fn default() -> Box<[T], Global>ⓘNotable traits for Box<R, Global>
impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
A: Allocator,
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
A: Allocator + 'static,
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
[src]pub fn default() -> Box<str, Global>ⓘNotable traits for Box<R, Global>
impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
A: Allocator,
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
A: Allocator + 'static,
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
[src]Creates an empty BinaryHeap<T>
.
impl<BlockSize> Default for BlockBuffer<BlockSize> where
BlockSize: Default + ArrayLength<u8>,
impl<BlockSize> Default for BlockBuffer<BlockSize> where
BlockSize: Default + ArrayLength<u8>,
pub fn default() -> BlockBuffer<BlockSize>
impl<FORMAT, STRICTNESS> Default for DurationNanoSeconds<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]
impl<FORMAT, STRICTNESS> Default for DurationNanoSeconds<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]impl<FORMAT, STRICTNESS> Default for DurationNanoSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]
impl<FORMAT, STRICTNESS> Default for DurationNanoSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]impl<FORMAT, STRICTNESS> Default for DurationMicroSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]
impl<FORMAT, STRICTNESS> Default for DurationMicroSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]impl<FORMAT, STRICTNESS> Default for TimestampMilliSeconds<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]
impl<FORMAT, STRICTNESS> Default for TimestampMilliSeconds<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]impl<FORMAT, STRICTNESS> Default for TimestampMicroSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]
impl<FORMAT, STRICTNESS> Default for TimestampMicroSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]impl<FORMAT, STRICTNESS> Default for TimestampSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]
impl<FORMAT, STRICTNESS> Default for TimestampSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]impl<FORMAT, STRICTNESS> Default for DurationSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]
impl<FORMAT, STRICTNESS> Default for DurationSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]impl<FORMAT, STRICTNESS> Default for TimestampSeconds<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]
impl<FORMAT, STRICTNESS> Default for TimestampSeconds<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]impl<FORMAT, STRICTNESS> Default for TimestampMicroSeconds<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]
impl<FORMAT, STRICTNESS> Default for TimestampMicroSeconds<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]impl<FORMAT, STRICTNESS> Default for DurationMilliSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]
impl<FORMAT, STRICTNESS> Default for DurationMilliSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]impl<FORMAT, STRICTNESS> Default for TimestampNanoSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]
impl<FORMAT, STRICTNESS> Default for TimestampNanoSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]impl<FORMAT, STRICTNESS> Default for TimestampMilliSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]
impl<FORMAT, STRICTNESS> Default for TimestampMilliSecondsWithFrac<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]impl<FORMAT, STRICTNESS> Default for TimestampNanoSeconds<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]
impl<FORMAT, STRICTNESS> Default for TimestampNanoSeconds<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]impl<FORMAT, STRICTNESS> Default for DurationMilliSeconds<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]
impl<FORMAT, STRICTNESS> Default for DurationMilliSeconds<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]impl<FORMAT, STRICTNESS> Default for DurationSeconds<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]
impl<FORMAT, STRICTNESS> Default for DurationSeconds<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]impl<FORMAT, STRICTNESS> Default for DurationMicroSeconds<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]
impl<FORMAT, STRICTNESS> Default for DurationMicroSeconds<FORMAT, STRICTNESS> where
FORMAT: Default + Format,
STRICTNESS: Default + Strictness,
[src]impl Default for MatchKind
impl Default for MatchKind
The default match kind is MatchKind::Standard
.
pub fn default() -> MatchKind
pub fn default() -> EndianSlice<'input, Endian>
impl<R> Default for UninitializedUnwindContext<R> where
R: Reader,
impl<R> Default for UninitializedUnwindContext<R> where
R: Reader,
pub fn default() -> UninitializedUnwindContext<R>
pub fn default() -> CompressionHeader64<E>
pub fn default() -> SectionTable<'data, Elf>
impl<'data, Elf> Default for SymbolTable<'data, Elf> where
Elf: FileHeader,
impl<'data, Elf> Default for SymbolTable<'data, Elf> where
Elf: FileHeader,
pub fn default() -> SymbolTable<'data, Elf>
pub fn default() -> SymbolMap<T>
impl<'data, Mach> Default for SymbolTable<'data, Mach> where
Mach: MachHeader,
impl<'data, Mach> Default for SymbolTable<'data, Mach> where
Mach: MachHeader,
pub fn default() -> SymbolTable<'data, Mach>
pub fn default() -> LoadCommandIterator<'data, E>
pub fn default() -> CompressionHeader32<E>
impl Default for DecompressorOxide
impl Default for DecompressorOxide
pub fn default() -> DecompressorOxide
pub fn default() -> DecompressorOxide
Create a new tinfl_decompressor with all fields set to 0.
impl Default for CompressorOxide
impl Default for CompressorOxide
pub fn default() -> CompressorOxide
pub fn default() -> CompressorOxide
Initialize the compressor with a level of 4, zlib wrapper and the default strategy.
pub fn default() -> Box<IndexSlice<I, [A]>, Global>ⓘNotable traits for Box<R, Global>
impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
A: Allocator,
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
A: Allocator + 'static,
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
Choose the default compression, a balance between speed and size.
impl Default for Config
impl Default for Config
The defaults are that of https://url.spec.whatwg.org/#idna
pub fn default() -> Config
pub fn default() -> ImageBuffer<P, Container>
impl Default for PixelDensity
impl Default for PixelDensity
pub fn default() -> PixelDensity
pub fn default() -> PixelDensity
Returns a pixel density with a pixel aspect ratio of 1
impl Default for CompressionOptions
impl Default for CompressionOptions
pub fn default() -> CompressionOptions
pub fn default() -> CompressionOptions
Returns the options describing the default compression level.
impl Default for CompressorOxide
impl Default for CompressorOxide
pub fn default() -> CompressorOxide
pub fn default() -> CompressorOxide
Initialize the compressor with a level of 4, zlib wrapper and the default strategy.
impl Default for DecompressorOxide
impl Default for DecompressorOxide
pub fn default() -> DecompressorOxide
pub fn default() -> DecompressorOxide
Create a new tinfl_decompressor with all fields set to 0.
Creates an empty iterator.
Creates an empty iterator.
impl Default for Style
impl Default for Style
pub fn default() -> Style
pub fn default() -> Style
Returns a style with no properties set. Formatting text using this style returns the exact same text.
use ansi_term::Style; assert_eq!(None, Style::default().foreground); assert_eq!(None, Style::default().background); assert_eq!(false, Style::default().is_bold); assert_eq!("txt", Style::default().paint("txt").to_string());
pub fn default() -> FuturesOrdered<Fut>
impl Default for LocalSet
impl Default for LocalSet
impl Default for Client<HttpConnector<GaiResolver>, Body>
impl Default for Client<HttpConnector<GaiResolver>, Body>
pub fn default() -> Client<HttpConnector<GaiResolver>, Body>
pub fn default() -> HashMap<K, V, S>
pub fn default() -> HashMap<K, V, S>
Creates an empty HashMap<K, V, S>
, with the Default
value for the hasher.
pub fn default() -> HashSet<T, S>
pub fn default() -> HashSet<T, S>
Creates an empty HashSet<T, S>
with the Default
value for the hasher.
Implementors
The default value is Value::Null
.
This is useful for handling omitted Value
fields when deserializing.
Examples
use serde_json::Value; #[derive(Deserialize)] struct Settings { level: i32, #[serde(default)] extras: Value, } let data = r#" { "level": 42 } "#; let s: Settings = serde_json::from_str(data)?; assert_eq!(s.level, 42); assert_eq!(s.extras, Value::Null);
impl Default for otter_api_tests::shapelib::LittleEndian
impl Default for otter_api_tests::shapelib::LittleEndian
pub fn default() -> LittleEndian
impl Default for TimestampPrecision
impl Default for TimestampPrecision
The default timestamp precision is seconds.
pub fn default() -> TimestampPrecision
impl Default for WriteStyle
impl Default for WriteStyle
pub fn default() -> WriteStyle
impl Default for DeferredNow
impl Default for DeferredNow
pub fn default() -> DeferredNow
impl Default for LogSpecBuilder
impl Default for LogSpecBuilder
pub fn default() -> LogSpecBuilder
Creates a new DefaultHasher
using new
.
See its documentation for more.
Constructs a new RandomState
.
impl Default for LogSpecification
impl Default for LogSpecification
pub fn default() -> LogSpecification
impl Default for Sha512Trunc256
impl Default for Sha512Trunc256
pub fn default() -> Sha512Trunc256ⓘNotable traits for Sha512Trunc256
impl Write for Sha512Trunc256
impl Default for FileOptions
impl Default for FileOptions
pub fn default() -> FileOptions
impl Default for InvalidOutputSize
impl Default for InvalidOutputSize
pub fn default() -> InvalidOutputSize
impl Default for QuotaValidFlags
impl Default for QuotaValidFlags
pub fn default() -> QuotaValidFlags
impl Default for UnixCredentials
impl Default for UnixCredentials
pub fn default() -> UnixCredentials
impl Default for OnceNonZeroUsize
impl Default for OnceNonZeroUsize
pub fn default() -> OnceNonZeroUsize
impl Default for Sha512Trunc224
impl Default for Sha512Trunc224
pub fn default() -> Sha512Trunc224ⓘNotable traits for Sha512Trunc224
impl Write for Sha512Trunc224
impl Default for UnixSocketAddr
impl Default for UnixSocketAddr
pub fn default() -> UnixSocketAddr
Creates an AtomicBool
initialized to false
.
impl<'_, I, T> Default for &'_ IndexSlice<I, [T]> where
I: Idx,
impl<'_, I, T> Default for &'_ IndexSlice<I, [T]> where
I: Idx,
pub fn default() -> &'_ IndexSlice<I, [T]>
impl<'_, I, T> Default for &'_ mut IndexSlice<I, [T]> where
I: Idx,
impl<'_, I, T> Default for &'_ mut IndexSlice<I, [T]> where
I: Idx,
pub fn default() -> &'_ mut IndexSlice<I, [T]>
impl<R, G, T> Default for ReentrantMutex<R, G, T> where
T: Default + ?Sized,
G: GetThreadId,
R: RawMutex,
impl<R, G, T> Default for ReentrantMutex<R, G, T> where
T: Default + ?Sized,
G: GetThreadId,
R: RawMutex,
pub fn default() -> ReentrantMutex<R, G, T>
impl<T> Default for OrderedFloat<T> where
T: Default,
impl<T> Default for OrderedFloat<T> where
T: Default,
pub fn default() -> OrderedFloat<T>
Creates an UnsafeCell
, with the Default
value for T.
impl<T, N> Default for GenericArray<T, N> where
T: Default,
N: ArrayLength<T>,
impl<T, N> Default for GenericArray<T, N> where
T: Default,
N: ArrayLength<T>,
pub fn default() -> GenericArray<T, N>
impl<T, U> Default for LazyTransform<T, U> where
T: Default,
impl<T, U> Default for LazyTransform<T, U> where
T: Default,
pub fn default() -> LazyTransform<T, U>
Return an empty ArrayString