[][src]Trait core_extensions::ConstDefault

pub trait ConstDefault: Sized {
    pub const DEFAULT: Self;
}

A const equivalent of the Default trait.

Features

Enabling the "const_generics" feature allows arrays of all lengths to implement this trait, otherwise it's only implemented for arrays up to 32 elements long.

Example

Implementing ConstDefault for a struct

// use core_extensions::const_default; // in newer versions of Rust.
#[macro_use(const_default)]
extern crate core_extensions;

use core_extensions::ConstDefault;
 
#[derive(Debug,PartialEq)]
struct Point<T>{
    x:T,
    y:T,
}

// `+ Copy` here is required for Rust 1.20 and 1.21,
// and can be removed from Rust 1.22 onwards.
impl<T> ConstDefault for Point<T>
where
    T: ConstDefault + Copy
{
    const DEFAULT: Self= Point{ x: T::DEFAULT,  y: T::DEFAULT };
}

assert_eq!( const_default!(Point<u8>), Point{x:0, y:0} );
assert_eq!( const_default!(Point<f32>), Point{x:0.0, y:0.0} );
assert_eq!( const_default!(Point<Option<()>>), Point{x:None, y:None} );

Associated Constants

pub const DEFAULT: Self[src]

The default value for Self.

Loading content...

Implementations on Foreign Types

impl<T: ConstDefault, const N: usize> ConstDefault for [T; N][src]

This is supported on crate feature const_params only.

When the "const_params" feature is disabled, the ConstDefault trait is implemented for arrays up to 32 elements long.

impl ConstDefault for ()[src]

impl<A> ConstDefault for (A,) where
    A: ConstDefault + Sized
[src]

impl<A, B> ConstDefault for (A, B) where
    A: ConstDefault + Sized,
    B: ConstDefault + Sized
[src]

impl<A, B, C> ConstDefault for (A, B, C) where
    A: ConstDefault + Sized,
    B: ConstDefault + Sized,
    C: ConstDefault + Sized
[src]

impl<A, B, C, D> ConstDefault for (A, B, C, D) where
    A: ConstDefault + Sized,
    B: ConstDefault + Sized,
    C: ConstDefault + Sized,
    D: ConstDefault + Sized
[src]

impl<A, B, C, D, E> ConstDefault for (A, B, C, D, E) where
    A: ConstDefault + Sized,
    B: ConstDefault + Sized,
    C: ConstDefault + Sized,
    D: ConstDefault + Sized,
    E: ConstDefault + Sized
[src]

impl<A, B, C, D, E, F> ConstDefault for (A, B, C, D, E, F) where
    A: ConstDefault + Sized,
    B: ConstDefault + Sized,
    C: ConstDefault + Sized,
    D: ConstDefault + Sized,
    E: ConstDefault + Sized,
    F: ConstDefault + Sized
[src]

impl<A, B, C, D, E, F, G> ConstDefault for (A, B, C, D, E, F, G) where
    A: ConstDefault + Sized,
    B: ConstDefault + Sized,
    C: ConstDefault + Sized,
    D: ConstDefault + Sized,
    E: ConstDefault + Sized,
    F: ConstDefault + Sized,
    G: ConstDefault + Sized
[src]

impl<A, B, C, D, E, F, G, H> ConstDefault for (A, B, C, D, E, F, G, H) where
    A: ConstDefault + Sized,
    B: ConstDefault + Sized,
    C: ConstDefault + Sized,
    D: ConstDefault + Sized,
    E: ConstDefault + Sized,
    F: ConstDefault + Sized,
    G: ConstDefault + Sized,
    H: ConstDefault + Sized
[src]

impl<A, B, C, D, E, F, G, H, I> ConstDefault for (A, B, C, D, E, F, G, H, I) where
    A: ConstDefault + Sized,
    B: ConstDefault + Sized,
    C: ConstDefault + Sized,
    D: ConstDefault + Sized,
    E: ConstDefault + Sized,
    F: ConstDefault + Sized,
    G: ConstDefault + Sized,
    H: ConstDefault + Sized,
    I: ConstDefault + Sized
[src]

impl<A, B, C, D, E, F, G, H, I, J> ConstDefault for (A, B, C, D, E, F, G, H, I, J) where
    A: ConstDefault + Sized,
    B: ConstDefault + Sized,
    C: ConstDefault + Sized,
    D: ConstDefault + Sized,
    E: ConstDefault + Sized,
    F: ConstDefault + Sized,
    G: ConstDefault + Sized,
    H: ConstDefault + Sized,
    I: ConstDefault + Sized,
    J: ConstDefault + Sized
[src]

impl<A, B, C, D, E, F, G, H, I, J, K> ConstDefault for (A, B, C, D, E, F, G, H, I, J, K) where
    A: ConstDefault + Sized,
    B: ConstDefault + Sized,
    C: ConstDefault + Sized,
    D: ConstDefault + Sized,
    E: ConstDefault + Sized,
    F: ConstDefault + Sized,
    G: ConstDefault + Sized,
    H: ConstDefault + Sized,
    I: ConstDefault + Sized,
    J: ConstDefault + Sized,
    K: ConstDefault + Sized
[src]

impl<A, B, C, D, E, F, G, H, I, J, K, L> ConstDefault for (A, B, C, D, E, F, G, H, I, J, K, L) where
    A: ConstDefault + Sized,
    B: ConstDefault + Sized,
    C: ConstDefault + Sized,
    D: ConstDefault + Sized,
    E: ConstDefault + Sized,
    F: ConstDefault + Sized,
    G: ConstDefault + Sized,
    H: ConstDefault + Sized,
    I: ConstDefault + Sized,
    J: ConstDefault + Sized,
    K: ConstDefault + Sized,
    L: ConstDefault + Sized
[src]

impl<A, B, C, D, E, F, G, H, I, J, K, L, M> ConstDefault for (A, B, C, D, E, F, G, H, I, J, K, L, M) where
    A: ConstDefault + Sized,
    B: ConstDefault + Sized,
    C: ConstDefault + Sized,
    D: ConstDefault + Sized,
    E: ConstDefault + Sized,
    F: ConstDefault + Sized,
    G: ConstDefault + Sized,
    H: ConstDefault + Sized,
    I: ConstDefault + Sized,
    J: ConstDefault + Sized,
    K: ConstDefault + Sized,
    L: ConstDefault + Sized,
    M: ConstDefault + Sized
[src]

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N> ConstDefault for (A, B, C, D, E, F, G, H, I, J, K, L, M, N) where
    A: ConstDefault + Sized,
    B: ConstDefault + Sized,
    C: ConstDefault + Sized,
    D: ConstDefault + Sized,
    E: ConstDefault + Sized,
    F: ConstDefault + Sized,
    G: ConstDefault + Sized,
    H: ConstDefault + Sized,
    I: ConstDefault + Sized,
    J: ConstDefault + Sized,
    K: ConstDefault + Sized,
    L: ConstDefault + Sized,
    M: ConstDefault + Sized,
    N: ConstDefault + Sized
[src]

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O> ConstDefault for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O) where
    A: ConstDefault + Sized,
    B: ConstDefault + Sized,
    C: ConstDefault + Sized,
    D: ConstDefault + Sized,
    E: ConstDefault + Sized,
    F: ConstDefault + Sized,
    G: ConstDefault + Sized,
    H: ConstDefault + Sized,
    I: ConstDefault + Sized,
    J: ConstDefault + Sized,
    K: ConstDefault + Sized,
    L: ConstDefault + Sized,
    M: ConstDefault + Sized,
    N: ConstDefault + Sized,
    O: ConstDefault + Sized
[src]

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> ConstDefault for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) where
    A: ConstDefault + Sized,
    B: ConstDefault + Sized,
    C: ConstDefault + Sized,
    D: ConstDefault + Sized,
    E: ConstDefault + Sized,
    F: ConstDefault + Sized,
    G: ConstDefault + Sized,
    H: ConstDefault + Sized,
    I: ConstDefault + Sized,
    J: ConstDefault + Sized,
    K: ConstDefault + Sized,
    L: ConstDefault + Sized,
    M: ConstDefault + Sized,
    N: ConstDefault + Sized,
    O: ConstDefault + Sized,
    P: ConstDefault + Sized
[src]

impl ConstDefault for i8[src]

impl ConstDefault for u8[src]

impl ConstDefault for i16[src]

impl ConstDefault for u16[src]

impl ConstDefault for i32[src]

impl ConstDefault for u32[src]

impl ConstDefault for i64[src]

impl ConstDefault for u64[src]

impl ConstDefault for f32[src]

impl ConstDefault for f64[src]

impl ConstDefault for bool[src]

impl ConstDefault for char[src]

impl<T: ?Sized> ConstDefault for PhantomData<T>[src]

impl<T> ConstDefault for Option<T>[src]

impl<'a> ConstDefault for &'a str[src]

impl<'a, T: 'a> ConstDefault for &'a [T][src]

impl<T: ConstDefault> ConstDefault for Wrapping<T>[src]

impl<T: ConstDefault> ConstDefault for Reverse<T>[src]

impl ConstDefault for AtomicUsize[src]

impl ConstDefault for AtomicIsize[src]

impl ConstDefault for AtomicBool[src]

impl<T: ConstDefault> ConstDefault for Cell<T>[src]

impl<T: ConstDefault> ConstDefault for RefCell<T>[src]

impl<T: ConstDefault> ConstDefault for UnsafeCell<T>[src]

impl ConstDefault for Duration[src]

impl ConstDefault for i128[src]

impl ConstDefault for u128[src]

impl<T: ConstDefault> ConstDefault for ManuallyDrop<T>[src]

impl ConstDefault for AtomicI8[src]

impl ConstDefault for AtomicU8[src]

impl ConstDefault for AtomicI16[src]

impl ConstDefault for AtomicU16[src]

impl ConstDefault for AtomicI32[src]

impl ConstDefault for AtomicU32[src]

impl ConstDefault for AtomicI64[src]

impl ConstDefault for AtomicU64[src]

impl<T> ConstDefault for Vec<T>[src]

impl ConstDefault for String[src]

Loading content...

Implementors

Loading content...