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

Significant of struct repr #6

Closed
ehsanmok opened this issue Feb 28, 2019 · 2 comments
Closed

Significant of struct repr #6

ehsanmok opened this issue Feb 28, 2019 · 2 comments

Comments

@ehsanmok
Copy link
Contributor

Could example the significance of using the following pattern over ffi in your code vs. empty struct despite having the same size and alignment?

#[repr(C)]
pub struct MyStruct {
    _private: [u8; 0],
}

vs.

#[repr(C)]
pub struct MyStruct;
@LaurentMazare
Copy link
Owner

This actually comes from the ffi documentation. Specifically for the private field, this bit is interesting:

By including a private field and no constructor, we create an opaque type that we can't instantiate outside of this module. (A struct with no field could be instantiated by anyone.)

@ehsanmok
Copy link
Contributor Author

I see! Thank you. It makes sense. That part must have been added somewhat recently.

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