-
-
Notifications
You must be signed in to change notification settings - Fork 338
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
please add getters to all settable things #619
Comments
This has come up before (#453 and #78 are worth a quick read). I think this use case makes a much better argument for why we need to add getters than for unit testing. I'm not sure whether to consolidate this into the discussion on #78 / #453 or whether to treat it as a new thing do you think your request is enough alike #78 to be useful there - if so, let's copy it over and close this? There aren't C# style getters in rust, mainly because idiomatically rust types that need them tend to just make the fields public - which might be the right option here (particularly if we mark the types non-exhaustive). The alternatives are crates that macro up getters like https://crates.io/crates/derive-getters or https://crates.io/crates/getset |
#78 is much larger in scope so, no, please don't merge this. This one is fundamentally simple Would you accept a PR using derive-getters? (Currently disappearing down a open source rabbit hole, originally working on gitui, it needs textarea, turns out that needs tweaks, turns out those fixes need tui changes..just posted issue to windows terminal needed by crossterm.. happy days) |
Yak shaving is a funny business.
I think this would be good to see. Because the builder methods currently use the field name (e.g. #[derive(Debug, Default, Clone, Eq, PartialEq, Hash, Getters)]
#[getset(get = "pub with_prefix")] Make sure to pay some attention to how the API docs render. I suspect the field level comments will not be good enough for the getters in some cases as we've often commented just the builder methods. Perhaps it's sufficient to just link to the setters from each field? |
Yup I saw that about names. But I like getters simplicity, you can just ask to generate all getters with a derive at the struct level. So now my next rabbit hole to get derive-getters to accept a prefix attribute at the struct level I just found out that it's not on GitHub so now I have to learn a different repo / issue / pr system. Sigh |
well i see that getset has the same feature, so thats good. FYI. The ultimate reason I am doing this is to get rid of 'tick infection'. Because |
Problem
My immediate example is that I need to look inside a
Block
being passed to me (I am a library that a tui app uses). I need to read theborder_style
andtitle
. But I think this is a general point, especially for a library that adds tui features (tui_textarea in my case)It would be nice if rust had c# style properties, but it does not, so this is a lot of sloggy typing
Solution
Add
get_xxx
fn to every struct that has anxxx
fn that sets the xxx property.Alternatives
The text was updated successfully, but these errors were encountered: