Trait sgx_tstd::default::Default1.0.0[][src]

pub trait Default {
    fn default() -> Self;
}

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.

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() -> Kind { 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() -> Kind { Kind::A }
}

Implementations on Foreign Types

impl Default for Duration
[src]

impl Default for Global
[src]

impl Default for sgx_ps_cap_t
[src]

impl Default for sgx_cpu_context_t
[src]

impl Default for sgx_ra_msg3_t
[src]

impl Default for sgx_mc_uuid_t
[src]

impl Default for ecc_param_t
[src]

impl Default for sgx_dh_session_role_t
[src]

impl Default for sgx_report_data_t
[src]

impl Default for sgx_ec256_public_t
[src]

impl Default for sgx_spid_t
[src]

impl Default for sgx_uswitchless_worker_event_t
[src]

impl Default for sgx_quote_t
[src]

impl Default for sgx_dh_msg1_t
[src]

impl Default for sgx_uswitchless_worker_type_t
[src]

impl Default for sgx_dh_msg3_t
[src]

impl Default for sgx_report_t
[src]

impl Default for sgx_misc_attribute_t
[src]

impl Default for sgx_basename_t
[src]

impl Default for sgx_dh_session_t
[src]

impl Default for sgx_thread_mutexattr_t
[src]

impl Default for sgx_dh_session_enclave_identity_t
[src]

impl Default for sgx_thread_condattr_t
[src]

impl Default for sgx_measurement_t
[src]

impl Default for sgx_exception_info_t
[src]

impl Default for sgx_rsa_result_t
[src]

impl Default for sgx_update_info_bit_t
[src]

impl Default for sgx_generic_ecresult_t
[src]

impl Default for sgx_status_t
[src]

impl Default for sgx_uswitchless_worker_stats_t
[src]

impl Default for sgx_ps_sec_prop_desc_t
[src]

impl Default for sgx_rsa3072_signature_t
[src]

impl Default for rsa_params_t
[src]

impl Default for sgx_key_request_t
[src]

impl Default for sgx_dh_msg2_t
[src]

impl Default for sgx_dh_msg3_body_t
[src]

impl Default for sgx_target_info_t
[src]

impl Default for sgx_ec256_signature_t
[src]

impl Default for sgx_rsa_key_type_t
[src]

impl Default for sgx_report_body_t
[src]

impl Default for sgx_ec256_dh_shared_t
[src]

impl Default for sgx_ra_msg1_t
[src]

impl Default for sgx_ec256_private_t
[src]

impl Default for sgx_exception_type_t
[src]

impl Default for sgx_ra_msg2_t
[src]

impl Default for sgx_ps_sec_prop_desc_ex_t
[src]

impl Default for sgx_platform_info_t
[src]

impl Default for sgx_uswitchless_config_t
[src]

impl Default for sgx_ra_key_type_t
[src]

impl Default for sgx_key_id_t
[src]

impl Default for sgx_quote_nonce_t
[src]

impl Default for sgx_cpu_svn_t
[src]

impl Default for sgx_rsa3072_key_t
[src]

impl Default for sgx_rsa3072_public_key_t
[src]

impl Default for sgx_device_status_t
[src]

impl Default for sgx_sealed_data_t
[src]

impl Default for sgx_exception_vector_t
[src]

impl Default for sgx_attributes_t
[src]

impl Default for sgx_aes_gcm_data_t
[src]

impl Default for sgx_quote_sign_type_t
[src]

Implementors