-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
Support #[builder(getter(...))]
attribute
#222
Conversation
#[allow(unused)] | ||
Inferred, |
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.
This should probably clarify what Inferred
means and why it's unused in a comment. Although see #222 (comment)
pub(crate) const DOCS_CONTEXT: &str = "builder struct's impl block"; | ||
|
||
pub(crate) fn parse_docs(meta: &syn::Meta) -> Result<super::SpannedKey<Vec<syn::Attribute>>> { | ||
crate::parsing::parse_docs_without_self_mentions(DOCS_CONTEXT, meta) | ||
} |
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 think it makes sense to extract this module. It's okay to just copy this small function into the getter
module. The DOCS_CONTEXT
isn't meant to be a cross-module-shared variable with such a generic name, it's meant to be module-local and describe the context where the docs will be pasted for the config param defined in that module
fn from_none() -> Option<Self> { | ||
None | ||
} |
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.
Isn't this already the default implementation of this trait method in FromMeta
?
Thanks for the feedback. I'm about done aside from that one comment above, just going to sleep now and finish up the tests in the morning. |
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.
LGTM, although I did just a quick review this time. Once new comments are fixed I'll merge this. I'll re-review the changes tomorrow, improve any other minor stuff, maybe update some of the guides, and do the minor release.
Cool, I do also have a need for the |
Pipeline should be good now too, I added a tiny bit to the init script and contributing docs |
I'm pushing my amendments and merging |
"`getter` attribute is experimental and requires \ | ||
\"experimental-getter\" cargo feature to be enabled; \ | ||
we would be glad to make this attribute stable if you find it useful; \ | ||
please leave a 👍 reaction under the issue https://github.com/elastio/bon/issues/221 \ |
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 believe you want to reference the new stabilize tracking issue here instead.
please leave a 👍 reaction under the issue https://github.com/elastio/bon/issues/221 \ | |
please leave a 👍 reaction under the issue https://github.com/elastio/bon/issues/225 \ |
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.
Yeah, I updated this code locally, although I can't push my changes to Kindness-Works:laz/221-getters even though there is this sentence in the PR metadata:
$ git push Kindness-Works pr/lazkindness/222:laz/221-getters
ERROR: Permission to Kindness-Works/bon.git denied to Veetaha.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
Maybe you have an org-wise rejection for writes from external contributors?
Anyway, I'll force-merge this PR and submit my amendments in a separate PR
Opened a followup PR #226
cc @lazkindness
# See more info at https://bon-rs.com/reference/builder/member/getter. | ||
# | ||
# We are considering stabilizing this attribute if you have a use for it. Please leave | ||
# a 👍 reaction under the issue https://github.com/elastio/bon/issues/221 if you need |
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.
Same here?
# a 👍 reaction under the issue https://github.com/elastio/bon/issues/221 if you need | |
# a 👍 reaction under the issue https://github.com/elastio/bon/issues/225 if you need |
Opened a followup PR #226 |
This feature has been released in bon 3.2.0. Thank you for the contribution! |
@lazkindness I opened an (unfinished yet) draft PR for |
Heads up, did a cc @lazkindness |
Resolves #221
Implements an experimental (and limited) version of a
getter
attribute to return references to already set values.Currently supported (for structs, methods, and functions):
#[builder(getter)]
#[builder(getter(name = "new_getter_name"))]
#[builder(getter(vis = "pub(crate)"))]
#[builder(getter(doc {}))]
In its current form it's not very "smart", so getters for a
String
return&String
and not&str
, for example, nor is copy / clone inferred and implemented for types which support them.See #221 for some more discussion on the future features.