Skip to content

Commit

Permalink
chore: address some pedantic clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed May 18, 2024
1 parent 4c89ade commit 937f921
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 22 deletions.
19 changes: 9 additions & 10 deletions confik-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod tests;
pub fn derive_macro_builder(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let target_struct = parse_macro_input!(input as DeriveInput);

match derive_macro_builder_inner(target_struct) {
match derive_macro_builder_inner(&target_struct) {
Ok(token_stream) => token_stream,
Err(err) => err.to_compile_error().into(),
}
Expand Down Expand Up @@ -599,7 +599,7 @@ impl ToTokens for Derive {
struct RootImplementer {
/// The ident/name of the target (the struct/enum the derive was called on).
///
/// To get the builder_name, see [`RootImplementer::builder_name`].
/// To get the builder name, see [`RootImplementer::builder_name`].
ident: Ident,

// #[darling(rename = "ident")]
Expand Down Expand Up @@ -716,12 +716,11 @@ impl RootImplementer {
// present...
//
// Therefore, conditionally add the `;`.
let terminator = if matches!(&self.data, ast::Data::Struct(fields) if fields.style.is_tuple())
{
Some(quote!(;))
} else {
None
};
let terminator = matches!(
&self.data,
ast::Data::Struct(fields) if fields.style.is_tuple(),
)
.then_some(quote!(;));

let (_impl_generics, type_generics, where_clause) = generics.split_for_impl();

Expand Down Expand Up @@ -895,8 +894,8 @@ impl RootImplementer {
}
}

fn derive_macro_builder_inner(target_struct: DeriveInput) -> syn::Result<proc_macro::TokenStream> {
let implementer = RootImplementer::from_derive_input(&target_struct)?;
fn derive_macro_builder_inner(target_struct: &DeriveInput) -> syn::Result<proc_macro::TokenStream> {
let implementer = RootImplementer::from_derive_input(target_struct)?;
implementer.check_valid()?;
let builder_struct = implementer.define_builder()?;
let builder_impl = implementer.impl_builder();
Expand Down
2 changes: 1 addition & 1 deletion confik/examples/defaulting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const FIELD2_DEFAULT: &str = "Hello World";

#[derive(Configuration, Debug, PartialEq, Eq)]
struct Config {
#[confik(default = 5usize)]
#[confik(default = 5_usize)]
field1: usize,
#[confik(default = FIELD2_DEFAULT)]
field2: String,
Expand Down
6 changes: 6 additions & 0 deletions confik/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ impl<'a, Target: Configuration> ConfigBuilder<'a, Target> {
}

/// Attempt to build from the provided sources.
///
/// # Errors
///
/// Returns an error if a required value is missing, a secret value was provided in a non-secret
/// source, or an error is returned from a source (e.g., invalid TOML). See [`Error`] for more
/// details.
pub fn try_build(&mut self) -> Result<Target, Error> {
if self.sources.is_empty() {
build_from_sources([Box::new(DefaultSource) as Box<dyn DynSource<_>>])
Expand Down
1 change: 1 addition & 0 deletions confik/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub enum Error {
impl Error {
/// Used in chaining [`MissingValue`] errors during [`crate::Configuration::try_build`].
#[doc(hidden)]
#[must_use]
pub fn prepend(self, path_segment: impl Into<Cow<'static, str>>) -> Self {
match self {
Self::MissingValue(err) => Self::MissingValue(err.prepend(path_segment)),
Expand Down
20 changes: 11 additions & 9 deletions confik/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,17 @@ where
sources
.into_iter()
// Convert each source to a `Target::Builder`
.map::<Result<Target::Builder, Error>, _>(|s: Box<dyn DynSource<Target::Builder> + 'a>| {
let debug = || format!("{:?}", s);
let res = s.provide().map_err(|e| Error::Source(e, debug()))?;
if s.allows_secrets().not() {
res.contains_non_secret_data()
.map_err(|e| Error::UnexpectedSecret(e, debug()))?;
}
Ok(res)
})
.map::<Result<Target::Builder, Error>, _>(
|source: Box<dyn DynSource<Target::Builder> + 'a>| {
let debug = || format!("{source:?}");
let res = source.provide().map_err(|e| Error::Source(e, debug()))?;
if source.allows_secrets().not() {
res.contains_non_secret_data()
.map_err(|e| Error::UnexpectedSecret(e, debug()))?;
}
Ok(res)
},
)
// Merge the builders
.reduce(|first, second| Ok(Target::Builder::merge(first?, second?)))
// If there was no data then we're missing values
Expand Down
2 changes: 1 addition & 1 deletion confik/tests/secret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ mod toml {

assert_matches!(
&target,
Error::UnexpectedSecret(path, _) if path.to_string().contains(&format!("`{}`", expected_path))
Error::UnexpectedSecret(path, _) if path.to_string().contains(&format!("`{expected_path}`"))
);
}

Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ clippy:

msrv := ```
cargo metadata --format-version=1 \
| jq -r 'first(.packages[] | select(.source == null and .name == "actix-tls")) | .rust_version' \
| jq -r 'first(.packages[] | select(.source == null and .rust_version)) | .rust_version' \
| sed -E 's/^1\.([0-9]{2})$/1\.\1\.0/'
```
msrv_rustup := "+" + msrv
Expand Down

0 comments on commit 937f921

Please # to comment.