Skip to content
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

section 4.4 final exercise problem with impl Display #266

Open
Lazerbeak12345 opened this issue Nov 20, 2021 · 0 comments
Open

section 4.4 final exercise problem with impl Display #266

Lazerbeak12345 opened this issue Nov 20, 2021 · 0 comments

Comments

@Lazerbeak12345
Copy link

Lazerbeak12345 commented Nov 20, 2021

Where in the docs did you come across this?

In section 4.4, in the last exercise (the one where it recommends use of FixedBitSet for storing alive/dead state).

Describe what about it does not make sense

During the adjustments in that answer, it doesn't touch the impl fmt::Display for Universe block, so it can't compile as that block needs updating or removal to still work.

Why does it not make sense?

It isn't clear that the impl fmt::Display for Universe block should be removed or tampered (it makes only a passing mention "Also, instead of rendering Unicode text, we'll switch to using the Canvas API.").

How could we improve it?

I have two ideas:

  1. Recommended This can be fixed during the "Rendering to Canvas Directly from Memory" section. We could add somewhere in that section to remove said block
  2. We could include how to fix the code:
use std::fmt;
impl fmt::Display for Universe {
   fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
       for row in 0..self.height { // changed
           for col in 0..self.width { // changed
               let idx = self.get_index(row, col); // changed
               let cell = self.cells[idx]; // changed
               let symbol = if cell { '◼' } else { '◻' }; // changed
               write!(f, "{}", symbol)?;
           }
           write!(f, "\n")?;
       }
       Ok(())
   }
}

I recommend solution 1 over 2 because the effected code is dead code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant