Skip to content

Types implementing Deref{,Mut} shouldn't have any other methods or public fields #13126

@sfackler

Description

@sfackler

For example, sync::RwLockWriteGuard implements Deref and DerefMut, implements the downgrade method, and has a public cond field. Since Rust doesn't have distinct . and -> operators, this makes for an API that can be confusing and ambiguous.

Adding an extra layer of indirection seems like a reasonable solution. It feels a bit strange to call methods of the wrapped type on an RAII lock guard anyways:

let locked_foo: RwLock<Foo> = ...;
let mut guard = locked_foo.write();
while !guard.get().is_foo() {
    guard.cond.wait();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions