[−][src]Struct show_notes::e002::Circle
This struct is simple but useful to see how borrowing and moving work.
Fields
x: f64
X position of the circle's origin.
y: f64
Y position of the circle's origin
r: f64
Radius of the circle
Methods
impl Circle
[src]
Implement some methods on the Circle
.
This lets use demonstrate both how methods work in general and specifically how they interact with the idea of ownership.
fn origin(r: f64) -> Circle
[src]
Creates a Circle
instance centered on the "origin" (x = 0, y = 0).
pub fn new(x: f64, y: f64, r: f64) -> Circle
[src]
Creates a Circle
instance centered on specified x, y values.
pub fn x_by_ref(&self) -> f64
[src]
Returns the value of Circle.x
, borrowing an immutable reference to
the circle to do it.
Because the reference is immutable, if you tried to do this---
self.x = 10;
---the compiler would not allow it.
pub fn x_by_mut_ref(&mut self) -> f64
[src]
Returns the value of Circle.x
, borrowing a mutable reference to the
circle and changing the value (demonstrating a situation in which you
would want to use a mutable rather than immutable reference).
pub fn by_take(self) -> f64
[src]
Returns the value of Circle.x
, taking ownership of the circle. As a
result of the change in ownership, the circle goes out of scope after
the method returns, so the circle instance will be inaccessible after
that.
Note that the item is taken as immutable, so attempting to change the internals will still fail. Ownership is orthogonal to immutability.
pub fn by_take_mut(self) -> f64
[src]
Returns the value of Circle.x
, taking ownership of a mutable circle.
Trait Implementations
Auto Trait Implementations
impl Send for Circle
impl Unpin for Circle
impl Sync for Circle
impl RefUnwindSafe for Circle
impl UnwindSafe for Circle
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,