refactor: box large Error variants (Command, Pkgar) to fix result_large_err
Boxing the Command(Command, ExitStatus) variant (204 bytes) and Pkgar(pkgar::Error) variant (272 bytes) reduces the Error enum from 272+ bytes to ~80 bytes, eliminating all 70 result_large_err warnings. Changes: - Error::Command(Command, ExitStatus) → Command(Box<(Command, ExitStatus)>) - Error::Pkgar(pkgar::Error) → Pkgar(Box<pkgar::Error>) - Updated 2 construction sites in fs.rs (Command) - Updated 1 construction site in package.rs (Pkgar) - Updated 1 From conversion in lib.rs (Pkgar) - Updated Display match in lib.rs (Command destructuring) This is a heap allocation on error paths only — zero cost on the happy path. Box<T> auto-implements Display/Debug when inner type does, so formatting is unchanged. Verification: cargo check ✅, cargo test --lib ✅ 38/38. Clippy: 74 → 4 warnings (70 eliminated).
This commit is contained in:
+2
-2
@@ -201,7 +201,7 @@ pub fn run_command(mut command: process::Command, stdout_pipe: &PtyOut) -> Resul
|
||||
.map_err(wrap_io_err!("waiting to exit"))?;
|
||||
|
||||
if !status.success() {
|
||||
return Err(Error::Command(command, status));
|
||||
return Err(Error::Command(Box::new((command, status))));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -289,7 +289,7 @@ pub fn run_command_stdin(
|
||||
let status = child.wait().map_err(wrap_io_err!("Spawning"))?;
|
||||
|
||||
if !status.success() {
|
||||
return Err(Error::Command(command, status));
|
||||
return Err(Error::Command(Box::new((command, status))));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
+1
-1
@@ -158,7 +158,7 @@ pub fn package_toml(
|
||||
pkgar_core::Packaging::LZMA2 => {
|
||||
let mut size = header
|
||||
.total_size()
|
||||
.map_err(|e| Error::Pkgar(pkgar::Error::Core(e)))?
|
||||
.map_err(|e| Error::Pkgar(Box::new(pkgar::Error::Core(e))))?
|
||||
as u64;
|
||||
let entries = package
|
||||
.read_entries()
|
||||
|
||||
+5
-4
@@ -43,9 +43,9 @@ pub enum Error {
|
||||
dst: PathBuf,
|
||||
context: &'static str,
|
||||
},
|
||||
Command(Command, ExitStatus),
|
||||
Command(Box<(Command, ExitStatus)>),
|
||||
Package(pkg::PackageError),
|
||||
Pkgar(pkgar::Error),
|
||||
Pkgar(Box<pkgar::Error>),
|
||||
Other(String),
|
||||
}
|
||||
|
||||
@@ -86,7 +86,8 @@ impl Display for Error {
|
||||
source
|
||||
)
|
||||
}
|
||||
Error::Command(command, exit_status) => {
|
||||
Error::Command(boxed) => {
|
||||
let (command, exit_status) = &**boxed;
|
||||
write!(
|
||||
f,
|
||||
"Failed to run [{:?}]: exited with status {}",
|
||||
@@ -174,7 +175,7 @@ impl From<pkgar::Error> for Error {
|
||||
path,
|
||||
context,
|
||||
},
|
||||
_ => Error::Pkgar(value),
|
||||
_ => Error::Pkgar(Box::new(value)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user