Trait sgx_tstd::clone::Clone1.0.0[][src]

#[lang = "clone"]
pub trait Clone {
#[must_use = "cloning is often expensive and is not expected to have side effects"]
fn clone(&self) -> Self; fn clone_from(&mut self, source: &Self) { ... } }

A common trait for the ability to explicitly duplicate an object.

Differs from Copy in that Copy is implicit and extremely inexpensive, while Clone is always explicit and may or may not be expensive. In order to enforce these characteristics, Rust does not allow you to reimplement Copy, but you may reimplement Clone and run arbitrary code.

Since Clone is more general than Copy, you can automatically make anything Copy be Clone as well.

Derivable

This trait can be used with #[derive] if all fields are Clone. The derived implementation of clone calls clone on each field.

How can I implement Clone?

Types that are Copy should have a trivial implementation of Clone. More formally: if T: Copy, x: T, and y: &T, then let x = y.clone(); is equivalent to let x = *y;. Manual implementations should be careful to uphold this invariant; however, unsafe code must not rely on it to ensure memory safety.

An example is an array holding more than 32 elements of a type that is Clone; the standard library only implements Clone up until arrays of size 32. In this case, the implementation of Clone cannot be derived, but can be implemented as:

#[derive(Copy)]
struct Stats {
   frequencies: [i32; 100],
}

impl Clone for Stats {
    fn clone(&self) -> Stats { *self }
}

Additional implementors

In addition to the implementors listed below, the following types also implement Clone:

Required Methods

Returns a copy of the value.

Examples

let hello = "Hello"; // &str implements Clone

assert_eq!("Hello", hello.clone());

Provided Methods

Performs copy-assignment from source.

a.clone_from(&b) is equivalent to a = b.clone() in functionality, but can be overridden to reuse the resources of a to avoid unnecessary allocations.

Implementations on Foreign Types

impl Clone for CannotReallocInPlace
[src]

impl Clone for AllocErr
[src]

impl Clone for Waker
[src]

impl Clone for TryFromSliceError
[src]

impl Clone for LocalWaker
[src]

impl Clone for LayoutErr
[src]

impl Clone for Layout
[src]

impl<T> Clone for Poll<T> where
    T: Clone
[src]

impl Clone for Duration
[src]

impl Clone for Global
[src]

impl Clone for sockaddr_un

impl Clone for timeval

impl Clone for stat64

impl Clone for sockaddr_ll

impl Clone for stat

impl Clone for sockaddr_in

impl Clone for timespec

impl Clone for SgxThreadData
[src]

impl Clone for addrinfo

impl Clone for sockaddr_nl

impl Clone for in6_addr

impl Clone for fd_set

impl Clone for sockaddr

impl Clone for sockaddr_storage

impl Clone for ipv6_mreq

impl Clone for SgxGlobalData
[src]

impl Clone for ip_mreq

impl Clone for pollfd

impl Clone for hostent

impl Clone for linger

impl Clone for sockaddr_in6

impl Clone for in_addr

impl Clone for tm

impl Clone for sigval

impl Clone for iovec

impl Clone for winsize

impl Clone for sgx_generic_ecresult_t
[src]

impl Clone for sgx_dh_msg3_t
[src]

impl Clone for sgx_exception_vector_t
[src]

impl Clone for sgx_aes_gcm_data_t
[src]

impl Clone for sgx_key_request_t
[src]

impl Clone for ecc_param_t
[src]

impl Clone for sgx_ra_key_type_t
[src]

impl Clone for sgx_exception_type_t
[src]

impl Clone for sgx_rsa3072_signature_t
[src]

impl Clone for sgx_rsa3072_public_key_t
[src]

impl Clone for sgx_ps_sec_prop_desc_ex_t
[src]

impl Clone for sgx_key_id_t
[src]

impl Clone for sgx_device_status_t
[src]

impl Clone for sgx_misc_attribute_t
[src]

impl Clone for sgx_platform_info_t
[src]

impl Clone for sgx_ra_msg3_t
[src]

impl Clone for sgx_dh_session_role_t
[src]

impl Clone for sgx_ps_sec_prop_desc_t
[src]

impl Clone for sgx_thread_condattr_t
[src]

impl Clone for sgx_uswitchless_worker_type_t
[src]

impl Clone for sgx_quote_t
[src]

impl Clone for sgx_ec256_signature_t
[src]

impl Clone for sgx_ra_msg1_t
[src]

impl Clone for sgx_update_info_bit_t
[src]

impl Clone for sgx_cpu_svn_t
[src]

impl Clone for rsa_params_t
[src]

impl Clone for sgx_ra_msg2_t
[src]

impl Clone for sgx_quote_sign_type_t
[src]

impl Clone for sgx_cpu_context_t
[src]

impl Clone for sgx_target_info_t
[src]

impl Clone for sgx_dh_session_enclave_identity_t
[src]

impl Clone for sgx_rsa_key_type_t
[src]

impl Clone for sgx_measurement_t
[src]

impl Clone for sgx_dh_msg3_body_t
[src]

impl Clone for sgx_ec256_dh_shared_t
[src]

impl Clone for sgx_dh_session_t
[src]

impl Clone for sgx_dh_msg2_t
[src]

impl Clone for sgx_uswitchless_worker_stats_t
[src]

impl Clone for sgx_basename_t
[src]

impl Clone for sgx_report_t
[src]

impl Clone for sgx_dh_msg1_t
[src]

impl Clone for sgx_ec256_public_t
[src]

impl Clone for sgx_uswitchless_worker_event_t
[src]

impl Clone for sgx_mc_uuid_t
[src]

impl Clone for sgx_exception_info_t
[src]

impl Clone for sgx_report_body_t
[src]

impl Clone for sgx_quote_nonce_t
[src]

impl Clone for sgx_spid_t
[src]

impl Clone for sgx_thread_mutexattr_t
[src]

impl Clone for sgx_ec256_private_t
[src]

impl Clone for sgx_ps_cap_t
[src]

impl Clone for sgx_status_t
[src]

impl Clone for sgx_sealed_data_t
[src]

impl Clone for sgx_report_data_t
[src]

impl Clone for sgx_rsa3072_key_t
[src]

impl Clone for sgx_rsa_result_t
[src]

impl Clone for sgx_attributes_t
[src]

impl Clone for SeekFrom
[src]

Implementors