Skip to content

Fix some clippy warnings #34

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

saulvaldelvira
Copy link

Hello. When building this crate clippy emits some warnings.

One of them is about the size of the neo4j::Result type.
Neo4jError has a ServerError variant that takes up a lot of space. This forces all Neo4jErrors, and thus
all neo4j::Results to be huge, which can impact performance.
The suggested solution is to wrap the ServerError on a Box. This reduces the size of a
Neo4jError from 184 bytes to 40 bytes (on my computer).

The other warnings were less important. Two of them were more of a style lint, the other was about an
unnecessary use of the format! macro.

P.D: This crate is amazing. I've used it for a school project, thank you!! :)

Copy link
Owner

@robsdedude robsdedude left a comment

Choose a reason for hiding this comment

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

Nice new clippy lints they've added 👏

I'm glad my project came in handy for you and thanks for taking the time to open this PR. Generally it's looking good. Just some minor comments.

@@ -104,7 +104,7 @@ pub enum Neo4jError {
/// * the server returns an error.
#[error("{error}")]
#[non_exhaustive]
ServerError { error: ServerError },
ServerError { error: Box<ServerError> },
Copy link
Owner

Choose a reason for hiding this comment

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

Since this is a user-facing (and breaking) API change, can you please add an entry to CHANGELOG.md? I suggest to classify this under "Improvements" and please also add the "⚠️".

Copy link
Owner

Choose a reason for hiding this comment

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

Also, this section of CONTRIBUTING.md might be relevant as well since you're changing the public API.

@@ -55,7 +55,7 @@ type BoxError = Box<dyn StdError + Send + Sync>;
/// the server version.
pub enum Neo4jError {
/// used when
/// * experiencing a connectivity error.
/// * experiencing a connectivity error.
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
/// * experiencing a connectivity error.
/// * experiencing a connectivity error.

Please don't remove the line breaks from the markdown docs 😇 There more places like this in the PR. I spare you repeating this comment there.

@saulvaldelvira
Copy link
Author

Done. I've added a line on the CHANGELOG.md and removed all the whitespace changes.
I've also removed the io::Error::other change because it is unstable on rust 1.70.

The servererror variant of neo4jerror is huge. on my computer it is 184
bytes. clippy warns us that it's not recommended to have an err variant
that big. the solution is to box the servererror, which requires a memory
allocation, but reduces the size of the result.
this way, we won't need to reserve that much stack space for every result.
errors are less common to occur, so the benefit of reducing the size of
all results should compensate for the memory allocation required in case
of a servererror.

see the details of this lint on the link below:
https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err>
The RecordBuffer::Transaction variant is empty. Clippy suggests
removing the struct pattern `{..}`.
Instead of using the format! macro, which creates a string, feed the
format directly to the trace! and debug! macros.
This achieves the same result, without creating an intermediate String.
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