-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
apply most clippy suggestions #6
apply most clippy suggestions #6
Conversation
@@ -48,9 +48,9 @@ impl From<ProfileTag> for Option<Profile> { | |||
|
|||
impl From<&Profile> for ProfileTag { | |||
fn from(profile: &Profile) -> Self { | |||
if profile == &Profile::Default { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally think this would look better as a match, but that's not my decision I'd say
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't do a traditionalmatch
, unfortunately, as Profile
is not an enum
. However, we could do something like:
match profile {
p if p == Profile::Default => ProfileTag::Default,
...
}
I think that'd be great.
@@ -98,7 +98,7 @@ pub fn diff_paths<P, B>(path: P, base: B) -> Option<PathBuf> | |||
} | |||
} | |||
|
|||
Some(comps.iter().map(|c| c.as_os_str()).collect::<PathBuf>().into()) | |||
Some(comps.iter().map(|c| c.as_os_str()).collect()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's up for debate if removing the turbofish here is a good idea. It might make it less clear, you'll have to look at the function signature to know the type it's collecting into.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with it.
',' | '{' | '}' | '[' | ']' => false, | ||
_ => true | ||
} | ||
!matches!(byte, ',' | '{' | '}' | '[' | ']') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks ugly, especially the !matches!
. I'm open to changing it back or to something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with it.
Value::String(Tag::Default, value.to_string().into()) | ||
impl From<&str> for Value { | ||
fn from(value: &str) -> Value { | ||
Value::String(Tag::Default, value.to_string()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was not actually a clippy suggestion, I saw myself that the lifetime could be elided here.
src/figment.rs
Outdated
@@ -287,7 +287,8 @@ impl Figment { | |||
/// ``` | |||
pub fn extract_inner<'a, T: Deserialize<'a>>(&self, key: &str) -> Result<T> { | |||
let merged = self.merged().map_err(|e| e.resolved(self))?; | |||
let inner = merged.find(key).ok_or(Kind::MissingField(key.to_string().into()))?; | |||
let inner = merged.find(key) | |||
.ok_or_else(|| Kind::MissingField(key.to_string().into()))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I'm not sure if the formatting was a good decision. Please tell me if I should change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only line would be preferred.
src/providers/data.rs
Outdated
.map_err(|e| de::Error::custom(e))?; | ||
|
||
Self::from_str(&source) | ||
Self::from_str(&std::fs::read_to_string(path).map_err(de::Error::custom)?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this is a lot simpler, we could keep the source variable part to make it more readable, like let source = std::fs::read_to_string(path).map_err(de::Error::custom)?; Self::from_str(&source)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are great! Just some minor comments.
src/figment.rs
Outdated
@@ -287,7 +287,8 @@ impl Figment { | |||
/// ``` | |||
pub fn extract_inner<'a, T: Deserialize<'a>>(&self, key: &str) -> Result<T> { | |||
let merged = self.merged().map_err(|e| e.resolved(self))?; | |||
let inner = merged.find(key).ok_or(Kind::MissingField(key.to_string().into()))?; | |||
let inner = merged.find(key) | |||
.ok_or_else(|| Kind::MissingField(key.to_string().into()))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only line would be preferred.
@@ -48,9 +48,9 @@ impl From<ProfileTag> for Option<Profile> { | |||
|
|||
impl From<&Profile> for ProfileTag { | |||
fn from(profile: &Profile) -> Self { | |||
if profile == &Profile::Default { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't do a traditionalmatch
, unfortunately, as Profile
is not an enum
. However, we could do something like:
match profile {
p if p == Profile::Default => ProfileTag::Default,
...
}
I think that'd be great.
src/providers/data.rs
Outdated
.map_err(|e| de::Error::custom(e))?; | ||
|
||
Self::from_str(&source) | ||
Self::from_str(&std::fs::read_to_string(path).map_err(de::Error::custom)?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do that.
@@ -98,7 +98,7 @@ pub fn diff_paths<P, B>(path: P, base: B) -> Option<PathBuf> | |||
} | |||
} | |||
|
|||
Some(comps.iter().map(|c| c.as_os_str()).collect::<PathBuf>().into()) | |||
Some(comps.iter().map(|c| c.as_os_str()).collect()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with it.
',' | '{' | '}' | '[' | ']' => false, | ||
_ => true | ||
} | ||
!matches!(byte, ',' | '{' | '}' | '[' | ']') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with it.
src/providers/data.rs
Outdated
@@ -294,19 +293,13 @@ pub trait Format: Sized { | |||
|
|||
/// Parses `string` as the data format `Self` as a `T` or returns an error | |||
/// if the `string` is an invalid `T`. | |||
fn from_str<'de, T: DeserializeOwned>(string: &'de str) -> Result<T, Self::Error>; | |||
fn from_str<T: DeserializeOwned>(string: &str) -> Result<T, Self::Error>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is backwards compatible.
Let's remove this change and just leave a note in the source code about changing it in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, because this is a trait that might be implemented by other crates. Got it.
3ceab26
to
64a56fe
Compare
I've applied changes according to your request. I hope this looks good! |
64a56fe
to
19ce965
Compare
Thank you! |
Hi again!
Here I just went through and applied all of the clippy suggestions that made sense in my opinion. Of course I'm open to still changing stuff if it doesn't fit the crate's style/standards.
There are two clippy warnings and one "error" still left:
This one I think is really just a nitpick; clippy would probably like you to remove the nested
value::value
module and move the code to the top-level module, but I don't think there's really a point in that.This is a definite false positive and should probably be reported to clippy if it isn't already; this warning should never apply to macros.
Not sure what to do about this one, but I doubt that it has any real impact.