Skip to content
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

Pp refresh #3

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Pp refresh #3

wants to merge 11 commits into from

Conversation

ppentchev
Copy link
Contributor

Hi,

What do you think about the attached (mostly trivial) commits that address some style issues reported by cargo fmt and cargo clippy with a couple of non-default Clippy categories allowed? (most of the clippy::restriction ones, some clippy::pedantic ones, and clippy::nursery) Of course, as the author of the de-regex crate the decision as to which of these make sense and which are just busy-work lies entirely with you :)

Thanks again, and keep up the great work!

G'luck,
Peter

Copy link
Owner

@vstroebel vstroebel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution.

I've aproved the following commit:
eaf0ea7 Reformat the source code using cargo fmt.
643a78c clippy::needless_borrow.
066c93f Fix clippy::single_char_lifetime_names.
9928960 Fix clippy::redundant_pub_crate.

For the other changes see the comments below

input,
regex,
}
pub const fn new(input: &'de str, regex: Regex) -> Deserializer {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a good use-case for making this const?
AFAIK creating a Regex isn't possible in a const context anyways.

@@ -2,6 +2,7 @@ use std::fmt::{Display, Formatter};

/// An error that occurred during deserialization.
#[derive(Debug)]
#[non_exhaustive]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think we should do this. Marking an error enum as non exhaustive makes some devs more lazy about error handling and there should be a good reason for doing this. The error handling of this crate is already quite weak and in would be better to improve this instead of allowing users to ignore errors.

fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
use Error::*;
match self {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This make the code more difficult to read without any benefit.

pub fn from_str<'a, T>(input: &'a str, regex: &str) -> std::result::Result<T, Error> where T: Deserialize<'a> {
let regex = Regex::new(&regex).map_err(Error::BadRegex)?;
from_str_regex(input, regex)
#[inline]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any benchmarks that show noticeable performance improvements marking this and other functions as inline?

where
T: Deserialize<'input>,
{
let rex = Regex::new(regex).map_err(Error::BadRegex)?;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name shadowing can be confusing, but i don't think this applies to regex here and replacing it with rex doesn't improve this.

struct Value {
name: String,
value: String,
}

impl Value {
fn parse<T>(&self) -> Result<T> where T: FromStr {
#[allow(clippy::map_err_ignore)]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to not ignore this error and make the parser error available in the caller instead of ignoring this problem...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants