-
Notifications
You must be signed in to change notification settings - Fork 4
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
Visibility of inner struct depends on visibility of field #11
Comments
i think that falls into unintended behavior category but am not entirely sure. i will have to preform some tests. thanks for being patient :). if it does fall under unintended behavior then i would be delighted to accept your help |
So I looked into it and currently it is expected behavior. Tuple Structs must have a field vis, The nested structure also must also have a visibility. Consider a case where you need a vis structure like this. pub struct Child;
pub(crate) struct Parent(pub(crate) Vec<Child>);
// aka
```rust
nestify::nest! {
pub(crate) struct Parent(pub(crate) Vec<pub struct Child>)
} When defining a regular tuple struct i had to make a compromise with the syntax. I could not figure out a way to create a "native" like syntax without having to share the vis across both the field and the child type def. nestify::nest! {
pub(crate) struct Parent(pub struct Child)
} |
Thanks for taking the time for looking into this! That's a pretty interesting corner case, and you're right, I don't think there's any way to cleanly solve this other than making up different syntax. Do you think it's worth documenting it, just in case someone else bumps into it? I can write a quick paragraph for the readme if you think so. |
Alternatively... would you be comfortable with introducing a non-native-lke syntax? Something like I don't really like that |
Writing a section in the documentation would be helpful I think. It should explain the tuple struct limitation, ie) Perhaps an empty generic could be used. nestify::nest! {
pub(super) struct Parent(pub <pub (crate) struct Child>)
} I think this is a pretty small edge case though to need a very specific visibility structure like this. |
I would rather not introduce too much new syntax. One of the goals of nestify is for someone who has never seen it before to be able to reasonably guess what is going on. |
Thanks for thinking of me! I don't have a lot of spare time, at least for the next couple of weeks, but if you don't mind me looking into it by then, I'd love to. I'll also get a PR rolling for the documentation on this limitation. I'm not sure about how #7 relates to this issue... maybe you're thinking of something like: nestify::nest! {
pub struct Parent(>pub struct Child)
} Which is consistent (although it doesn't look very nice) with the syntax for field attributes ( |
sorry about my haphazard issue management haha. this is my first real GitHub project. |
Actually, I'd like to take a deeper look into this issue first, since I've been bit by it a few times! If I understood right, the main issue is when the inner type is directly a declaration, which as you said, I don't think it's solvable without new syntax... but what about cases when the inner type not a declaration, but may contain one? For example nestify::nest! {
pub struct Purchase(Vec<pub struct Inner>);
} I'd say there's no ambiguity here against nestify::nest! {
pub struct Purchase(pub Vec<pub struct Inner>);
} Maybe I'm being naive, but some sort of lookahead at the visibility token could tell us whether it's followed by Would you be fine with me trying to put up a PR to that effect? |
Yes i believe that is correct. I the vast majority of the time there would be no ambiguity. I would happily accept a PR. Please allow the user to directly specify both visibilities if they want to as to not be a breaking change. |
I was writing this small snippet
And found that I can't access the
TripPurchase
struct externally, it's private. However if I make the fieldpub
, I can:Is this expected? It feels weird to me since it means the inner
pub
is mostly useless. Also, I'd say my first snippet is desirable for many patterns, for example if I want to hide the structure to force the use of a constructor to ensure invariants are held.If this is not actually expected and a bug, I may be able to lend a hand to fix it.
The text was updated successfully, but these errors were encountered: