diff options
author | cc <cc@localhost> | 2025-08-20 19:00:55 -0700 |
---|---|---|
committer | cc <cc@localhost> | 2025-08-20 19:05:09 -0700 |
commit | 98f1bf9c4345eadcf2b15902f3a30d7c8483bb9e (patch) | |
tree | 35de43adb5e93b66a783548e0d210d1308c99a3d | |
parent | b0ff49fdd4ae82af5cf89180078ea7314072c29f (diff) |
Simplify Error Handling
-rw-r--r-- | src/binfile.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/binfile.rs b/src/binfile.rs index 9b50a70..a43f568 100644 --- a/src/binfile.rs +++ b/src/binfile.rs @@ -1,14 +1,14 @@ -pub fn dump_u32_vec(file_name: &str, data: Vec<u32>) -> Result<(), String> { +use std::io::{Error,ErrorKind}; + +pub fn dump_u32_vec(file_name: &str, data: Vec<u32>) -> Result<(), Error> { use std::fs::File; use std::io::Write; if let Ok(mut file) = File::create(file_name) { for value in data { - if let Err(error) = file.write_all(&value.to_le_bytes()) { - return Err(error.to_string()); - } + file.write_all(&value.to_le_bytes())?; } } else { - return Err(String::from("Error creating file")); + return Err(Error::new(ErrorKind::Other, "Error creating file")); } Ok(()) } |