Skip to content

Stop using public newtype structs to wrap private types #9667

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

Closed
sfackler opened this issue Oct 1, 2013 · 0 comments · Fixed by #9693
Closed

Stop using public newtype structs to wrap private types #9667

sfackler opened this issue Oct 1, 2013 · 0 comments · Fixed by #9693
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup.

Comments

@sfackler
Copy link
Member

sfackler commented Oct 1, 2013

std::rt uses this a lot, for example:

pub struct TcpStream(~RtioTcpStreamObject);

This doesn't properly encapsulate the private type inside, since client code can dereference the TcpStream to get at it. According to #5489, newtype structs aren't intended to be able to hide their internals. The easiest solution is to probably switch to single-element structs, e.g.:

pub struct TcpStream {
    priv inner: ~RtioTcpStreamObject
}
bors added a commit that referenced this issue Oct 3, 2013
UnboundedPipeStream is still a newtype since process::set_stdio needs to
look into its internals.

Closes #9667
@bors bors closed this as completed in 019b131 Oct 3, 2013
flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 21, 2022
add new lint `seek_to_start_instead_of_rewind `

changelog: `seek_to_start_instead_of_rewind`: new lint to suggest using `rewind` instead of `seek` to start

Resolve rust-lang#8600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant