Skip to content

Wrap the Level enum in a newtype to prevent matching on it? #118

Description

@valadaptive

The Level enum has always had variants that might not be present depending on the target architecture--for instance, Level::Neon doesn't exist on anything other than aarch64.

However, #105 changes things so that Level::Fallback can now also be absent. This means that depending on the architecture and statically-enabled target features, every enum variant has a chance of being missing. As a result, trying to match on the Level enum is a footgun--there is always some architecture on which the match statement will fail.

I ran into this trying to port Vello to the latest (unreleased) version of fearless_simd; it extensively uses matches!(level, Level::Fallback(_)).

This makes me wonder if we should move the enum part of Level into a private field, making it impossible to match on it entirely. If needed, we could add always-present methods like Level::is_fallback(), Level::is_neon(), etc. that return false if the architecture doesn't match.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    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