From 9b613a629dc54c321b2909dd63bc9b47f0dc9cca Mon Sep 17 00:00:00 2001 From: 0x009922 <43530070+0x009922@users.noreply.github.com> Date: Mon, 22 Apr 2024 06:28:18 +0900 Subject: [PATCH] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ⭐️NINIKA⭐️ Signed-off-by: 0x009922 <43530070+0x009922@users.noreply.github.com> --- config/base/derive/src/lib.rs | 12 +++++------- config/base/src/read.rs | 12 ++++++++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/config/base/derive/src/lib.rs b/config/base/derive/src/lib.rs index f8e1faf0430..5b79596eca1 100644 --- a/config/base/derive/src/lib.rs +++ b/config/base/derive/src/lib.rs @@ -321,7 +321,7 @@ mod ast { let combined = if attr_nested { Self::Nested - }else { + } else { Self::Parameter { default: attr_default.unwrap_or_default(), env: match (attr_env, attr_env_custom) { @@ -397,20 +397,18 @@ mod ast { return vec![]; } - let mut found = None; - - if let syn::Type::Path(type_path) = ty { + let found = if let syn::Type::Path(type_path) = ty { if let Some(last_segment) = type_path.path.segments.last() { match &last_segment.arguments { syn::PathArguments::AngleBracketed(args) if args.args.len() == 1 => { if let syn::GenericArgument::Type(ty) = args.args.first().expect("should be exactly 1") { - found = Some((Some(ty), &last_segment.ident)); + Some((Some(ty), &last_segment.ident)) } } - syn::PathArguments::None => found = Some((None, &last_segment.ident)), - _ => {} + syn::PathArguments::None => Some((None, &last_segment.ident)), + _ => None, } } } diff --git a/config/base/src/read.rs b/config/base/src/read.rs index c0da1d2380b..7137cef463e 100644 --- a/config/base/src/read.rs +++ b/config/base/src/read.rs @@ -73,14 +73,22 @@ impl Error { /// and finally, construct an exhaustive error report with as many errors, accumulated along the /// way, as possible. pub struct ConfigReader { - sources: Vec, + /// The namespace this [`ConfigReader`] is handling. All the `ParameterId` handled will be prefixed with it. nesting: Vec, + /// File sources for the config + sources: Vec, + /// Environment variables source for the config + env: Box, + /// Errors accumulated per each file errors_by_source: BTreeMap>>, + /// Errors accumulated from the environment variables errors_in_env: Vec>, + /// A list of all the parameters that have been requested from this reader. Used to report unused (unknown) parameters in the toml file existing_parameters: BTreeSet, + /// A list of all required parameters that have been requested, but were not found missing_parameters: BTreeSet, + /// A runtime guard to prevent dropping the [`ConfigReader`] without handing errors bomb: DropBomb, - env: Box, } impl Debug for ConfigReader {