KEMBAR78
Use Rc for LineEntry to reduce memory consumption by Tom01098 · Pull Request #393 · dotenv-linter/dotenv-linter · GitHub
Skip to content

Conversation

@Tom01098
Copy link
Contributor

Closes #388.

✔ Checklist:

@Tom01098
Copy link
Contributor Author

I was wondering how to enforce that new was called, currently anyone could just use the struct creation syntax.

I found this which recommended adding a private field to the struct. clippy warned against this, using non_exhaustive instead, but I found this only works at the crate level.

So what's most 'idiomatic'? I'm not sure where to go from here (but that's really irrelevant to this PR!).

@mgrachev mgrachev added this to the v3.1.0 milestone Mar 21, 2021
Copy link
Member

@mgrachev mgrachev left a comment

Choose a reason for hiding this comment

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

@Tom01098 👋 Thank you for your contribution 🚀

I have left some comments. Please take a look at them 👀

@mgrachev
Copy link
Member

I was wondering how to enforce that new was called, currently anyone could just use the struct creation syntax.

I found this which recommended adding a private field to the struct. clippy warned against this, using non_exhaustive instead, but I found this only works at the crate level.

So what's most 'idiomatic'? I'm not sure where to go from here (but that's really irrelevant to this PR!).

I like more the way where you can create a public Struct with a private field:

pub struct LineEntry {
    pub number: usize,
    pub file: Rc<FileEntry>,
    pub raw_string: String,

    /// Used in ExtraBlankLineFixer
    is_deleted: bool,
}

This struct you can't create like this LineEntry { ... } - only using the new method.

If you want to deal with the private field you can create a method like this:

pub fn is_deleted(&self) -> bool {
    self.is_deleted
}

Tom01098 and others added 2 commits March 21, 2021 11:02
@codecov-io
Copy link

codecov-io commented Mar 21, 2021

Codecov Report

Merging #393 (ca70166) into master (492d3a4) will increase coverage by 0.25%.
The diff coverage is 100.00%.

❗ Current head ca70166 differs from pull request most recent head bb5d7c8. Consider uploading reports for the commit bb5d7c8 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #393      +/-   ##
==========================================
+ Coverage   95.32%   95.57%   +0.25%     
==========================================
  Files          37       37              
  Lines        2376     2375       -1     
==========================================
+ Hits         2265     2270       +5     
+ Misses        111      105       -6     
Impacted Files Coverage Δ
src/common.rs 100.00% <100.00%> (ø)
src/common/line_entry.rs 98.01% <100.00%> (+2.09%) ⬆️
src/fixes/ending_blank_line.rs 100.00% <100.00%> (ø)
src/lib.rs 89.92% <100.00%> (+2.13%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 492d3a4...bb5d7c8. Read the comment docs.

@Tom01098
Copy link
Contributor Author

@mgrachev thanks for the review, I should have corrected everything as requested. (If only I remembered conventional commits didn't end with a full stop I wouldn't have to keep force pushing!!)

@mgrachev mgrachev merged commit 23a6762 into dotenv-linter:master Mar 21, 2021
@mgrachev
Copy link
Member

@Tom01098 Thank you for your help ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Use Rc for LineEntry to reduce memory consumption

3 participants