fn print<T: ToString>(v: T) {
> We say that “print is generic over type T, where T implements Stringify” fn print<T: ToString>(v: T) {
> We say that “print is generic over type T, where T implements Stringify”Show is a very common but generic word in programming, for showing plots, showing message boxes, showing anything really. Not knowing Haskell I would not have expected it to convert an object to a string.
On the doc of ToString you can find the following note:
>This trait is automatically implemented for any type which implements the Display trait. As such, ToString shouldn't be implemented directly: Display should be implemented instead, and you get the ToString implementation for free.
I think ToString exists mostly in order to have a more convenient API to get a String out of a display-able type, otherwise if you used Display directly you'd have to use a variant of that boilerplate every time: https://doc.rust-lang.org/src/alloc/string.rs.html#2185-2192
If you were actually reading it aloud, I would strongly avoid that use of the word “where”, because it’ll be confused with a where clause:
fn print<T>(v: T) where T: ToString
The two are semantically identical, but they put the constraint in different places, so using the word “where” will confuse things, especially when it leads to you repeating the “T” in a way that where clauses do but the first form doesn’t.For myself, I would probably read the original line of code as “function print, generic over type tee implementing to string, taking parameter vee of type tee”.
The where clause version I’d read as “function print, generic over type tee, taking parameter vee of type tee, where tee implements to string”.