Skip to content

Document the usage scenario of "as" keyword for trait coercion #86287

@cher-nov

Description

@cher-nov

I've just stumbled about such an error:

an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object

It seems that the second part of it is about syntax like this:

<SomeType as Into<i32>>::into( ... ))

But these scenarios don't seem to be documented on the as page in the official docs:
https://doc.rust-lang.org/1.82.0/std/keyword.as.html

It states that as can be used only to "cast between types, or rename an import".

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions