[][src]Struct show_notes::e002::Circle

pub struct Circle {
    pub x: f64,
    pub y: f64,
    pub r: f64,
}

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---

This example is not tested
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

impl Debug for Circle[src]

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]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]