Struct show_notes::e019::BJustClonePoint
source · pub struct BJustClonePoint {
x: f64,
y: f64,
z: f64,
}
Expand description
A struct which implements Clone
but not Copy
.
Examples
If you don’t do anything, the item will be moved on assignment:
ⓘ
let a_point = BJustClonePoint::origin();
let cloned_point = a_point; // <- moves the value
println!("{:?}", a_point); // <- compile error!
println!("{:?}", cloned_point);
The output is just what we would expect from the discussion on the show:
error[E0382]: use of moved value: `a_point`
--> <anon>:6:18
|
5 | let cloned_point = a_point; // <- moves the value
| ------------ value moved here
6 | println!("{:?}", a_point); // <- compile error!
| ^^^^^^^ value used here after move
|
= note: move occurs because `a_point` has type `show_notes::e019::BJustClonePoint`, which does not implement the `Copy` trait
But you can manually call the clone
method, and it will work:
let a_point = BJustClonePoint::origin();
let cloned_point = a_point.clone();
println!("{:?}", a_point); // <- not a problem
println!("{:?}", cloned_point);
Fields§
§x: f64
§y: f64
§z: f64
Implementations§
source§impl BJustClonePoint
impl BJustClonePoint
pub fn origin() -> BJustClonePoint
Trait Implementations§
source§impl Clone for BJustClonePoint
impl Clone for BJustClonePoint
source§fn clone(&self) -> BJustClonePoint
fn clone(&self) -> BJustClonePoint
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl RefUnwindSafe for BJustClonePoint
impl Send for BJustClonePoint
impl Sync for BJustClonePoint
impl Unpin for BJustClonePoint
impl UnwindSafe for BJustClonePoint
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more