Skip to content

Cannot destructure the self argument #7613

@brendanzab

Description

@brendanzab

Currently we can destructure function arguments:

fn foo((x, y, z): (int, int, int)) -> int {
    x * y * z
}

assert_eq!(foo((1, 2, 3)), 6)

But there is no way of destructuring the self argument in methods. I don't know what kind of syntax this would involve, but the following sample shows a possibility:

trait Foo {
    fn foo(&self) -> int;
}

impl Foo for (int, int, int) {
    fn foo(&self @ &(x, y, z)) -> int {
        x * y * z
    }
}

assert_eq!((1i, 2i, 3i).foo(), 6);

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-grammarArea: The grammar of Rust

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions