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

Allow to use on private structs #46

Open
njam opened this issue Oct 20, 2020 · 2 comments
Open

Allow to use on private structs #46

njam opened this issue Oct 20, 2020 · 2 comments

Comments

@njam
Copy link

njam commented Oct 20, 2020

Using PackedStruct on private structs results in an error:

error[E0446]: private type `FooPacked` in public interface
  --> lib/foo.rs:13:10
   |
13 | #[derive(PackedStruct)]
   |          ^^^^^^^^^^^^ can't leak private type
14 | #[packed_struct(endian = "msb", bit_numbering = "msb0")]
15 | struct FooPacked {
   | - `FooPacked` declared as private
   |
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info

Is it possible to make it usable on private (and pub(crate)) structs too?

Environment:

  • Rust 1.46.0
  • packed_struct 0.3.0
@rudib
Copy link
Member

rudib commented Oct 21, 2020

pub(crate) didn't exist back then, so a bunch of things will have to be upgraded for this to work, but yes, for now, everything has to be public. You can always declare your module as private and your lib won't export these types.

@mich101mich
Copy link

From looking at the source code, it seems the only reason why this error occurs is because this code creates a pub function using the type. But that function is only used in one place, so simply removing the pub or declaring the function inside of the other function gets rid of this error and allows deriving on structs with any visibility.

Is there a reason why this is not the case?

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

3 participants