Skip to content

Commit d098faa

Browse files
committed
tutorial: Clarify description of trait inheritance
1 parent 21c9d08 commit d098faa

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

doc/tutorial.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -2127,15 +2127,15 @@ This usage of traits is similar to Java interfaces.
21272127

21282128
We can write a trait declaration that _inherits_ from other traits, called _supertraits_.
21292129
Types that implement a trait must also implement its supertraits.
2130-
2131-
For example, we can define a `Circle` trait that only types that also have the `Shape` trait can have:
2130+
For example,
2131+
we can define a `Circle` trait that inherits from `Shape`.
21322132

21332133
~~~~
21342134
trait Shape { fn area(&self) -> float; }
21352135
trait Circle : Shape { fn radius(&self) -> float; }
21362136
~~~~
21372137

2138-
Now, implementations of `Circle` methods can call `Shape` methods:
2138+
Now, we can implement `Circle` on a type only if we also implement `Shape`.
21392139

21402140
~~~~
21412141
# trait Shape { fn area(&self) -> float; }
@@ -2153,6 +2153,8 @@ impl CircleStruct: Shape {
21532153
}
21542154
~~~~
21552155

2156+
Notice that methods of `Circle` can call methods on `Shape`, as our
2157+
`radius` implementation calls the `area` method.
21562158
This is a silly way to compute the radius of a circle
21572159
(since we could just return the `circle` field), but you get the idea.
21582160

0 commit comments

Comments
 (0)