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

Save formatted map to string #4. Also, apply cargo fmt #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jpedrick
Copy link

@jpedrick jpedrick commented Jan 7, 2024

Enable saving a map to a string using formatters to bypass file output.

Copy link
Owner

@unrenamed unrenamed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jpedrick. Thanks for this PR. I'd be happy to merge your changes once you deal with my review comments. I'm open to discuss any follow-up questions of yours.

May I also ask you to write the commit(s) messages to match the conventional commits spec? Check the repo history for more examples.

Comment on lines +50 to +52
fn format(&self) -> String {
std::string::String::new()
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format method in ImageWrapper seems like a workaround. In the context of images, the string formatter doesn't make much sense, does it? And documenting this behavior complicates the library API.

Consider letting Rust handle this more idiomatically at compile time. To achieve this, we only need StringWrapper to implement another trait (e.g. custom Display or MazeDisplay), like this:

image

This approach also eliminates the confusion caused by the Saveable trait being aware of the format method.

@@ -41,6 +41,16 @@ impl OrthogonalMaze {
let data = formatter.format(&self.grid);
Saveable::save(&data, path)
}

// Saves a maze into a file to a given path using a given formatter
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be changed to match the format method implementation.

Comment on lines +46 to +53
pub fn format<F, T>(&self, formatter: F) -> String
where
F: Formatter<T>,
T: Saveable,
{
let data = formatter.format(&self.grid);
Saveable::format(&data)
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned that this PR could potentially decrease the overall code coverage percentage, leading to CI check failures. I'd appreciate it if you add some integration tests to tests/maze.rs to ensure comprehensive coverage for the newly introduced logic.

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

Successfully merging this pull request may close these issues.

2 participants