I have tried using the code in list 10.13 with the notify function added and calling it by :-
tweet.notify()
notify(tweet)
notify(&tweet)
tweet.notify() says it doesn't implement display so I tried adding #[derive(Debug)] to the Tweet structure and it then compiles but returns nothing ? How do you use this function ?
notify is a free function there, rather than one defined on Tweet or as part of the Summary trait, and it doesn't have a self parameter, so you can't use method call syntax (tweet.notify()). The right way to call it (assuming tweet is a Tweet) is just notify(&tweet) (playground example).
I'm not sure what you did to get an error saying it doesn't implement Display.
Thanks for that I understand now. Also I have struggled with the explanation of the self word and you have made it a lot clearer. I am finding the Rust book hard going so far especially the chapter on traits.
The line println!("With parameter {}", notify(&tweet)); Caused the display problem
With debug added to the structure and {?} I got () returned.
Part of how traits work builds on how method syntax and associated functions work, so you may find it helpful to review chapter 5.3 (Method Syntax).
Ah, I suspected you might be trying to print the output of notify(). Notice that notify isn't declared with a return type, so it returns the single-valued unit type (), which doesn't implement Display (since it doesn't make much sense to print it normally). The () type does implement Debug though, so you can print it with {:?} (and it will just print ()), and that explains the behaviour you observed. Implementing Debug for Tweet makes no difference here, since notify doesn't return a Tweet. The body of notify has a println, so it does the printing itself rather than returning a string for you to print.
The code is working now. I think I had the code working before using RustRover but because I had too small an output window the two strings appeared but scrolled up so all you could see is-
With Parameter ().
It is a lot clearer now thanks.