Skip to content

Stop using public newtype structs to wrap private types #9667

@sfackler

Description

@sfackler

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-cleanupCategory: PRs that clean code up or issues documenting cleanup.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions