Skip to content

Should the BitFlags trait subtrait BitAnd et al.? #293

@PatchMixolydic

Description

@PatchMixolydic

I'm currently using bitflags to implement collision bitmasks in a game engine. Of course, since different games use collision for different things, I decided to try making my collider type generic over the mask type using the BitFlags trait. However, this didn't quite work:

error[E0369]: no implementation for `M & M`
   --> triplicata/src/collision.rs:222:53
    |
222 | what_collided: self.accept_mask & other.generate_mask,
    |                ---------------- ^ ------------------- M
    |                |
    |                M
    |
help: consider further restricting this bound
    |
157 | impl<M: BitFlags + std::ops::BitAnd<Output = M>> Hitbox<M> {
    |                  ++++++++++++++++++++++++++++++

Since the types created by bitflags! always implement BitAnd (alongside several other traits), it might be convenient for BitFlags to subtrait BitAnd et al. Is this feasible?

(I realize I could probably just use BitAnd as a bound on its own in this case, but I'd like to push users towards using bitflags to define their bitmasks.)

cc #262

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