rust: box ConfigValueParseError to avoid large result types
clippy emits a warning that all the Result types are way too large
because of HgError includes ConfigValueParseError as one of the variants,
so its size is 136 bytes.
By boxing ConfigValueParseError we're hopefully making everything faster
"for free".
--- a/rust/hg-core/src/config/mod.rs Wed Feb 22 02:08:11 2023 +0100
+++ b/rust/hg-core/src/config/mod.rs Mon Feb 27 18:24:29 2023 +0000
@@ -64,7 +64,7 @@
}
#[derive(Debug)]
-pub struct ConfigValueParseError {
+pub struct ConfigValueParseErrorDetails {
pub origin: ConfigOrigin,
pub line: Option<usize>,
pub section: Vec<u8>,
@@ -73,6 +73,9 @@
pub expected_type: &'static str,
}
+// boxed to avoid very large Result types
+pub type ConfigValueParseError = Box<ConfigValueParseErrorDetails>;
+
impl fmt::Display for ConfigValueParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// TODO: add origin and line number information, here and in
@@ -354,14 +357,14 @@
match self.get_inner(section, item) {
Some((layer, v)) => match parse(&v.bytes) {
Some(b) => Ok(Some(b)),
- None => Err(ConfigValueParseError {
+ None => Err(Box::new(ConfigValueParseErrorDetails {
origin: layer.origin.to_owned(),
line: v.line,
value: v.bytes.to_owned(),
section: section.to_owned(),
item: item.to_owned(),
expected_type,
- }),
+ })),
},
None => Ok(None),
}