.
, , : let () = ...;.
, 1- :
9 | let () = self;
| ^^ expected &Self, found ()
:
16 | let () = self;
| ^^ expected &Circle, found ()
, HasArea , .
, self? .
, , HasArea. , , , , , HasArea.
, . , :
trait HasArea: Debug {
fn area(&self) -> f64;
}
Self: HasArea + Debug, , self HasArea Debug.
: , HasArea. Circle.
, self fn area(&self) &Circle.
, &Circle, , &Circle. ( ), .
.
, :
struct Segment(Point, Point);
impl Segment {
fn length(&self) -> f64;
}
trait Segmentify {
fn segmentify(&self) -> Vec<Segment>;
}
trait HasPerimeter {
fn has_perimeter(&self) -> f64;
}
HasPerimeter , .
impl<T> HasPerimeter for T
where T: Segmentify
{
fn has_perimeter(&self) -> f64 {
let mut total = 0.0;
for s in self.segmentify() { total += s.length(); }
total
}
}
self ? &T.
T? , Segmentify.
, T, , Segmentify HasPerimeter, ( println("{:?", self);, T Debug).