Closed rapodaca closed 5 years ago
Did you include the code to implement std::fmt::Display
? The ToString
trait is implemented for all T
where T: Display
:
By implementing the Display trait from Rust's standard library, we can add a way to format a structure in a user-facing manner. This will also automatically give us a to_string method.
use std::fmt; impl fmt::Display for Universe { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { for line in self.cells.as_slice().chunks(self.width as usize) { for &cell in line { let symbol = if cell == Cell::Dead { 'â—»' } else { 'â—¼' }; write!(f, "{}", symbol)?; } write!(f, "\n")?; } Ok(()) } }
If you include that code, it should resolve those errors you are seeing.
Closing this. Feel free to reopen if you need further help. Thanks!
Where in the docs did you come across this?
https://rustwasm.github.io/docs/book/game-of-life/implementing.html
Describe what about it does not make sense
The example code does not appear complete enough to compile.
Why does it not make sense?
to_string
does not appear to have been givenHow could we improve it?
It would be nice to see a complete listing for the file
lib.rs
at the end of the page found at:https://rustwasm.github.io/docs/book/game-of-life/implementing.html
I'm not sure if I just missed something or if documentation is in fact missing. Here's what I have for
lib.rs
just at:My error is:
to_string
found for type&Universe
in the current scope --> src/lib.rs:44:14= note: the method
to_string
exists but the following trait bounds were not satisfied:&Universe : std::string::ToString
Universe : std::string::ToString
= help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an itemto_string
, perhaps you need to implement it: candidate #1:std::string::ToString
error: aborting due to previous error
For more information about this error, try
rustc --explain E0599
. error: Could not compilewasm-game-of-life
.To learn more, run the command again with --verbose. Error: Compiling your crate to WebAssembly failed Caused by: failed to execute
cargo build
: exited with exit code: 101