October 2018
Beginner
180 pages
4h 48m
English
If the self value is immutably borrowed into a function, then that function has read-only access to the value. This is useful in many situations, because it lets us call the function without making a copy of the self value for it to operate on, and without making the compiler ensure that the rules of write access are maintained.
Here's an example of a function that immutably borrows self:
impl Point2D { // ... pub fn magnitude(&self) -> f64 { return (self.x.powi(2) + self.y.powi(2)).sqrt(); }}
, or in other words, the distance between the point stored in self and the origin of the coordinate system.The ...
Read now
Unlock full access