Skip to content
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

annotation to not create a "new" method #114

Open
lolbinarycat opened this issue May 24, 2024 · 4 comments
Open

annotation to not create a "new" method #114

lolbinarycat opened this issue May 24, 2024 · 4 comments

Comments

@lolbinarycat
Copy link

i have a self-referential struct and i would like to name its public constructor "new" for consistency with other types in my crate, however, due to the auto-generated method created by ouroboros, this is not possible.

@someguynamedjosh
Copy link
Owner

It is generally recommended that if you are going to make a public-facing API based on an Ouroboros struct then you wrap the self-referencing struct in your own struct and add the methods you want to define to your struct. (This is called the 'newtype' pattern and it is fairly common in Rust.)

@lolbinarycat
Copy link
Author

that reccomendation doesn't appear anywhere in the documentation, and in fact the visibility rules seem to imply you can use it directly on a public struct.

@someguynamedjosh
Copy link
Owner

The visibility rules are there so that you can use it at whatever level you need in your library. It is intended that you will never use it on a public struct that users of your library would interact with, but since there is no detectable difference between "pub in a module which is not itself public" and "pub so that everyone who uses this library can see this struct," the macro cannot enforce this recommendation.

@lolbinarycat
Copy link
Author

It is intended that you will never use it on a public struct that users of your library would interact with

then that intent should be documented.

since there is no detectable difference between "pub in a module which is not itself public" and "pub so that everyone who uses this library can see this struct," the macro cannot enforce this recommendation.

pub(crate) exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants