`foo.Bar::method()`: new syntax to disambiguate the method call

use std::fmt::Debug;
trait Bar where Self: Debug {
    fn method(&self) {
        println!("Bar for {:?}", self);
    }
}

trait Baz where Self: Debug {
    fn method(&self) {
        println!("Bar for {:?}", self);
    }
}

#[derive(Debug)]
struct Foo;

impl Bar for Foo {}
impl Baz for Foo {}

fn main() {
    let foo = Foo;
    // for the moment the only way to work,
    // but hurts writing and reading.
    Bar::method(&foo);
    Baz::method(&foo);

    // propose this new syntax,
    // nice to write and nice to read,
    // especially many function calls chained together.
    foo.Bar::method(); // Bar::method(&foo);
    foo.Baz::method(); // Baz::method(&foo);
}

1 Like

5 posts were merged into an existing topic: Idea: Paths in method names