pub trait MirroredClone<S: Speed>: Sized {
// Required method
fn mirrored_clone(&self) -> Self;
// Provided method
fn fast_mirrored_clone(&self) -> Self
where S: FastSpeed { ... }
}Expand description
Get clones that share all semantically-important mutable state.
The goal is that mutating one mirrored clone affects every clone. Different mirrored clones should, from their public interfaces, act identically, with some exceptions like memory addresses.
This can be achieved via reference counting (e.g., Rc or Arc), or by simply
not having any mutable state to share at all (e.g. a zero-sized type like (), or a reference
to a type without internal mutability, like &'static str).
Per-clone mutable data is permissible, so long as the effects of mutating that data do not
cause mirrored clones to behave differently in a potentially-observable way.
Clones of types like Option<T> or u32 are not considered to be mirrored clones, as
counterexamples.
§Exceptions
- A type implementing
MirroredClonemay specify that certain methods or accesses are not subject to these guarantees. Debugshould be assumed to be an exception. Intentionally worsening the life of someone debugging your type is not a goal.- Memory addresses which are different per-clone, but are not mutated by that clone (except when a user moves the value). Trivially, mirrored clones do not have the same address, and some of their data may be inlined into the type. If any reference to that data is exposed, a user would likely be able to determine what data is inlined into the type and what is inlined. That’s already visible in the source code, anyway. Unless some semantically-important function of the type depends on the address of it or its data, it’s unimportant.
- TLDR of above bullet: users should not assume that references returned from different mirrored clones refer to the same value, only that those values behave the same.
Required Methods§
Sourcefn mirrored_clone(&self) -> Self
fn mirrored_clone(&self) -> Self
Get a clone that shares all semantically-important mutable state with its source.
The goal is that mutating one mirrored clone affects every clone. Different mirrored clones should, from their public interfaces, act identically, with some exceptions like memory addresses.
Read MirroredClone for more.
Provided Methods§
Sourcefn fast_mirrored_clone(&self) -> Selfwhere
S: FastSpeed,
fn fast_mirrored_clone(&self) -> Selfwhere
S: FastSpeed,
Get a clone that shares all semantically-important mutable state with its source.
The goal is that mutating one mirrored clone affects every clone. Different mirrored clones should, from their public interfaces, act identically, with some exceptions like memory addresses.
Read MirroredClone for more.
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.
Implementations on Foreign Types§
Source§impl<S: Speed> MirroredClone<S> for Infallible
impl<S: Speed> MirroredClone<S> for Infallible
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed> MirroredClone<S> for ()
impl<S: Speed> MirroredClone<S> for ()
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed> MirroredClone<S> for PhantomPinned
impl<S: Speed> MirroredClone<S> for PhantomPinned
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed> MirroredClone<S> for RangeFull
impl<S: Speed> MirroredClone<S> for RangeFull
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, R> MirroredClone<S> for fn() -> R
impl<S: Speed, R> MirroredClone<S> for fn() -> R
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, R, T1> MirroredClone<S> for fn(T1) -> R
impl<S: Speed, R, T1> MirroredClone<S> for fn(T1) -> R
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, R, T1, T2> MirroredClone<S> for fn(T1, T2) -> R
impl<S: Speed, R, T1, T2> MirroredClone<S> for fn(T1, T2) -> R
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, R, T1, T2, T3> MirroredClone<S> for fn(T1, T2, T3) -> R
impl<S: Speed, R, T1, T2, T3> MirroredClone<S> for fn(T1, T2, T3) -> R
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, R, T1, T2, T3, T4> MirroredClone<S> for fn(T1, T2, T3, T4) -> R
impl<S: Speed, R, T1, T2, T3, T4> MirroredClone<S> for fn(T1, T2, T3, T4) -> R
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, R, T1, T2, T3, T4, T5> MirroredClone<S> for fn(T1, T2, T3, T4, T5) -> R
impl<S: Speed, R, T1, T2, T3, T4, T5> MirroredClone<S> for fn(T1, T2, T3, T4, T5) -> R
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, R, T1, T2, T3, T4, T5, T6> MirroredClone<S> for fn(T1, T2, T3, T4, T5, T6) -> R
impl<S: Speed, R, T1, T2, T3, T4, T5, T6> MirroredClone<S> for fn(T1, T2, T3, T4, T5, T6) -> R
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, R, T1, T2, T3, T4, T5, T6, T7> MirroredClone<S> for fn(T1, T2, T3, T4, T5, T6, T7) -> R
impl<S: Speed, R, T1, T2, T3, T4, T5, T6, T7> MirroredClone<S> for fn(T1, T2, T3, T4, T5, T6, T7) -> R
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, R, T1, T2, T3, T4, T5, T6, T7, T8> MirroredClone<S> for fn(T1, T2, T3, T4, T5, T6, T7, T8) -> R
impl<S: Speed, R, T1, T2, T3, T4, T5, T6, T7, T8> MirroredClone<S> for fn(T1, T2, T3, T4, T5, T6, T7, T8) -> R
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, R, T1, T2, T3, T4, T5, T6, T7, T8, T9> MirroredClone<S> for fn(T1, T2, T3, T4, T5, T6, T7, T8, T9) -> R
impl<S: Speed, R, T1, T2, T3, T4, T5, T6, T7, T8, T9> MirroredClone<S> for fn(T1, T2, T3, T4, T5, T6, T7, T8, T9) -> R
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, R, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> MirroredClone<S> for fn(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) -> R
impl<S: Speed, R, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> MirroredClone<S> for fn(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) -> R
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, R, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> MirroredClone<S> for fn(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) -> R
impl<S: Speed, R, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> MirroredClone<S> for fn(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) -> R
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, R, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> MirroredClone<S> for fn(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) -> R
impl<S: Speed, R, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> MirroredClone<S> for fn(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) -> R
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, T> MirroredClone<S> for Empty<T>
impl<S: Speed, T> MirroredClone<S> for Empty<T>
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, T: ?Sized> MirroredClone<S> for Rc<T>
impl<S: Speed, T: ?Sized> MirroredClone<S> for Rc<T>
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, T: ?Sized> MirroredClone<S> for Weak<T>
impl<S: Speed, T: ?Sized> MirroredClone<S> for Weak<T>
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, T: ?Sized> MirroredClone<S> for Arc<T>
impl<S: Speed, T: ?Sized> MirroredClone<S> for Arc<T>
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, T: ?Sized> MirroredClone<S> for Weak<T>
impl<S: Speed, T: ?Sized> MirroredClone<S> for Weak<T>
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, T: ?Sized> MirroredClone<S> for PhantomData<T>
impl<S: Speed, T: ?Sized> MirroredClone<S> for PhantomData<T>
fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, T: ?Sized> MirroredClone<S> for Pin<Rc<T>>
Available on crate feature alloc only.
impl<S: Speed, T: ?Sized> MirroredClone<S> for Pin<Rc<T>>
alloc only.fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, T: ?Sized> MirroredClone<S> for Pin<Weak<T>>
Available on crate feature alloc only.
impl<S: Speed, T: ?Sized> MirroredClone<S> for Pin<Weak<T>>
alloc only.fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, T: ?Sized> MirroredClone<S> for Pin<Arc<T>>
Available on crate feature alloc only.
impl<S: Speed, T: ?Sized> MirroredClone<S> for Pin<Arc<T>>
alloc only.fn mirrored_clone(&self) -> Self
Source§impl<S: Speed, T: ?Sized> MirroredClone<S> for Pin<Weak<T>>
Available on crate feature alloc only.
impl<S: Speed, T: ?Sized> MirroredClone<S> for Pin<Weak<T>>
alloc only.