-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Write up default methods for the tutorial. #11270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -2094,12 +2095,13 @@ fn head<T: Clone>(v: &[T]) -> T { | |||
} | |||
~~~~ | |||
|
|||
This says that we can call `head` on any type `T` | |||
as long as that type implements the `Clone` trait. | |||
The bounded type parameter `T: Clone` says that `head` is polymorphic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe say "can be called with any type T
"? I think we want to avoid PL jargon in the tutorial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pcwalton OK, I changed this and a couple other minor things.
r? @pcwalton |
types to be exactly as it is for `int`, above: | ||
|
||
~~~~ | ||
impl Printable for f32 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# trait Printable { fn print(&self); }
is missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, thanks. Fixed.
I've been wanting to explain default methods in the tutorial for ages. While I was at it I tried to clarify some other parts of the traits section. I'm sure this could be improved further; suggestions welcome.
I've been wanting to explain default methods in the tutorial for ages. While I was at it I tried to clarify some other parts of the traits section. I'm sure this could be improved further; suggestions welcome.