# HG changeset patch # User Arseniy Alekseyev # Date 2023-02-27 18:24:29 # Node ID af9d050f2bb8bd2c4048a11998c6038a05a8fb90 # Parent 3f3fca243dcaf3f0089372eec12d3195fcb20e7c 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". diff --git a/rust/hg-core/src/config/mod.rs b/rust/hg-core/src/config/mod.rs --- a/rust/hg-core/src/config/mod.rs +++ b/rust/hg-core/src/config/mod.rs @@ -64,7 +64,7 @@ pub enum ConfigSource { } #[derive(Debug)] -pub struct ConfigValueParseError { +pub struct ConfigValueParseErrorDetails { pub origin: ConfigOrigin, pub line: Option, pub section: Vec, @@ -73,6 +73,9 @@ pub struct ConfigValueParseError { pub expected_type: &'static str, } +// boxed to avoid very large Result types +pub type ConfigValueParseError = Box; + 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 @@ impl Config { 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), }