pub trait UseCloned: Clone { }
ergonomic_clones #132290)
Trait for objects whose Clone impl is lightweight (e.g. reference-counted)
Cloning an object implementing this trait should in general:
The UseCloned trait does not provide a method; instead, it indicates that Clone::clone is lightweight, and allows the use of the .use syntax.
Values can be .used by adding .use postfix to the value you want to use.
fn foo(f: Foo) {
// if `Foo` implements `Copy` f would be copied into x.
// if `Foo` implements `UseCloned` f would be cloned into x.
// otherwise f would be moved into x.
let x = f.use;
// ...
}
Use closures allow captured values to be automatically used. This is similar to have a closure that you would call .use over each captured value.
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
impl UseCloned for bool
impl UseCloned for char
impl UseCloned for f16
impl UseCloned for f32
impl UseCloned for f64
impl UseCloned for f128
impl UseCloned for i8
impl UseCloned for i16
impl UseCloned for i32
impl UseCloned for i64
impl UseCloned for i128
impl UseCloned for isize
impl UseCloned for u8
impl UseCloned for u16
impl UseCloned for u32
impl UseCloned for u64
impl UseCloned for u128
impl UseCloned for usize
impl<T> UseCloned for Option<T>where
T: UseCloned,impl<T> UseCloned for NonZero<T>where
T: ZeroablePrimitive,impl<T, A> UseCloned for Rc<T, A>where
A: Allocator + Clone,
T: ?Sized,impl<T, A> UseCloned for std::rc::Weak<T, A>where
A: Allocator + Clone,
T: ?Sized,impl<T, A> UseCloned for Arc<T, A>where
A: Allocator + Clone,
T: ?Sized,impl<T, A> UseCloned for std::sync::Weak<T, A>where
A: Allocator + Clone,
T: ?Sized,impl<T, E> UseCloned for Result<T, E>where
T: UseCloned,
E: UseCloned,
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/clone/trait.UseCloned.html