Skip to content

Guide: Confusing description for newtype idiom #20037

Closed
@crumblingstatue

Description

@crumblingstatue

In http://doc.rust-lang.org/guide.html#tuple-structs-and-newtypes:

We call this a 'newtype,' because it lets you create a new type that's a synonym for another one

This might cause the reader to think that struct Foo(Bar) creates type Foo, which is a synonym for Bar, and they can be used interchangeably, as with a type alias (or typedef in C).

This is not the case. A newtype declaration creates a distinct type, which cannot be used interchangeably with the type of its underlying representation. I think this should be clarified.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions