Skip to content

Pp refresh - #3

Open
ppentchev wants to merge 11 commits into
vstroebel:mainfrom
ppentchev:pp-refresh
Open

Pp refresh#3
ppentchev wants to merge 11 commits into
vstroebel:mainfrom
ppentchev:pp-refresh

Conversation

@ppentchev

Copy link
Copy Markdown
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

@vstroebel vstroebel left a comment

Copy link
Copy Markdown
Owner

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

Comment thread src/de.rs
input,
regex,
}
pub const fn new(input: &'de str, regex: Regex) -> Deserializer {

Copy link
Copy Markdown
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.

Comment thread src/error.rs

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

Copy link
Copy Markdown
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.

Comment thread src/error.rs
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
use Error::*;
match self {

Copy link
Copy Markdown
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.

Comment thread src/lib.rs
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
Copy Markdown
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?

Comment thread src/lib.rs
where
T: Deserialize<'input>,
{
let rex = Regex::new(regex).map_err(Error::BadRegex)?;

Copy link
Copy Markdown
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.

Comment thread src/de.rs

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

Copy link
Copy Markdown
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