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

Make FlashAlgorithm saveable #85

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions probe-rs/src/probe/flash/flasher.rs
Expand Up @@ -101,6 +101,13 @@ impl FlashAlgorithm {
pub fn new(definition: &str) -> Result<Self, AlgorithmParseError> {
serde_yaml::from_str(definition)
}

pub fn write_to_file(&self, file_name: impl AsRef<str>) {
use std::io::Write;
let s = serde_yaml::to_string(self).unwrap();
let mut file = std::fs::File::create(file_name.as_ref()).unwrap();
file.write_all(s.as_bytes()).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no need to go through a String here. The method should also return a Result instead of unwrapping.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I now introduced an error enum. Not sure if that's the right way.

}
}

#[derive(Debug)]
Expand Down