Skip to content

From<bool> for integers not implemented? #46109

Closed
@therealprof

Description

@therealprof

I would find it incredibly useful to being able to cast a bool to another type so I can shift it around to generate bitmasks but ALAS this is not possible at the moment due to missing From trait impls:

error[E0277]: the trait bound `u32: core::convert::From<bool>` is not satisfied

Using as instead works fine but is frowned upon by clippy if the type is not a bool but a different type instead:

warning: casting u16 to u32 may become silently lossy if types change

Since the code in question is automatically generated it would be great if there was one common implementation that can (and should) be used for all types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions