-
Notifications
You must be signed in to change notification settings - Fork 45
Move to a Renderer
when for displaying a Snippet
#67
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9076cbf
feat: Add `Renderer`
Muscraft d0c65b2
fix!: Move format options to `Renderer`
Muscraft 4affdfb
fix!: Move to a new `StyleSheet`
Muscraft dfd4e87
fix!: Switch to `anstyle` for color
Muscraft 79f657e
fix!: Move `Margin` to `renderer`
Muscraft da45f48
fix!: Make `display_list` private
Muscraft d45fbd4
refactor(display_list): Remove `From` impls
Muscraft a9bf385
refactor(display_list): Take a reference to `StyleSheet`
Muscraft 748b792
refactor(renderer): Make functions `const`
Muscraft b0848f7
chore(renderer): Add doc comments
Muscraft a1007dd
fix!: Move around items in the public api
Muscraft 71b1eb5
refactor: Move `display_list` under `renderer`
Muscraft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
chore(renderer): Add doc comments
- Loading branch information
commit b0848f70cdf54b4601bd01d4ae99ce4c63a80be9
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
question
: Why do you need those setters, why not make the properties public?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 did it because it is easier (and cleaner) to edit one specific field than making the fields public. The other thing is I believe it makes adding a field not a breaking change, but I do not know for certain.
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 understand how is it cleaner. Comparing:
vs
Can you explain further?
That can be achieved via https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute
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.
That's true I forgot about that. I will switch things over
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 was looking at making them public, and I realized what I meant by cleaner.
vs
It makes it so that
renderer
is not mutable and things can be chained together (omittingrenderer
each time).It follows the builder pattern which I am a fan for smaller structs, for larger structs I do think making fields public is a good idea.
If you would still like me to change it to be public fields I can but it will take me a moment to refactor.
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.
That's not correct. The renderer still has to be mutable for the setters to work (you're consuming them btw.
mut self
).The builder pattern is useful when your setters actually perform computations, invariant validation etc. In this case, your builder is the struct itself, so exposing it as such allows customers to use any Rust patterns to construct it.
By hiding it you're relying on custom uninspectable API to achieve the same.
It's a glorified version of:
vs just:
and let customers create it and operate on it any way they want. You can add helper impl methods (like you do with
plain
), but taking away ability to operate on the fields without any reason seems like a way that limits your downstream consumers from being able to interact with the struct in ways that you don't necessarily have to be able to even predict.In other words, if at the moment of consumption, you don't care how this struct has been constructred (maybe someone created their own methods to build the Renderer, or merge two), and you don't perform any validation, or variant locking, then just let it be an open struct and let people use all of Rust expressiveness to operate on it.
Saying that - this is my opinion, not a strong requirement - I will not try to block your PR on that, so if my arguments are not convincing to you, continue with this API and I'll r+ 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.
You can: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=6ddedead395636105b9830d26ab0e663
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.
Thats within the same visibility. I don't think you can if you don't have visibility.
One benefit I've seen to builder is the ability to evolve an API, particularly for evolving styles. You'll also see builder used in a lot of the ecosystem when no validation is done.
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, good call. Yeah, ability to use
..
would be nice.I'm generally supportive of builder patterns when there's logic involved. I find it inelegant when we have a plain struct and we populate it with dummy getters/setters.
But as I stated, this is my preference, and I'm not intending to push for it any further. I support the direction the author of the PR decides to take.
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 can see the merits of both and could go either way on this. Even though it is a breaking change, we could always change in the future. I'd say we should go with the builder (for now).