Skip to content

Support tuples in match arms #7

@klinvill

Description

@klinvill

It would be nice to have support for pattern matching against tuples. In particular, I'd like to be able to write something like:

    #[define]
    fn equiv_options<T>(v1: &Option<T>, v2: &Option<T>) -> bool {
        match (v1, v2) {
            (Option::<T>::Some(inner1), Option::<T>::Some(inner2)) => true,
            (Option::<T>::None, Option::<T>::None) => true,
            _ => false,
        }
    }

but currently such a match pattern would require instead writing:

    #[define]
    fn equiv_options<T>(v1: &Option<T>, v2: &Option<T>) -> bool {
        match v1 {
            Option::<T>::Some(inner1) => {
                match v2 {
                    Option::<T>::Some(inner2) => true,
                    Option::<T>::None => false,
                }
            },
            Option::<T>::None => {
                match v2 {
                    Option::<T>::Some(inner2) => false,
                    Option::<T>::None => true,
                }
            }
        }
    }

Of course, writing my desired match statement with the wildcard also requires #3 to be added, but support for matching against tuples should be added as well to allow for writing the match arms based on semantic meaning (e.g. I'd like to be able to group the true arms together and the false arms together).

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