Uniform function call syntax: Difference between revisions

Content deleted Content added
moved the citation for the coupling hazard; it's what the earlier text alludes to.
Fryguy9 (talk | contribs)
q and g are very difficult to visually parse (e.g. q.g), so switch to a,b,c
Line 43:
 
trait Foo {
fn fa(&self);
fn gb(&self);
}
 
trait Bar {
fn gb(&self);
}
 
Line 54:
 
impl Foo for Qux {
fn fa(&self) { println!("Qux’s implementation of Foo::fa"); }
fn gb(&self) { println!("Qux’s implementation of Foo::gb"); }
}
 
impl Bar for Qux {
fn g(&self) { println!("Qux’s implementation of Bar::gb"); }
}
 
fn main() {
let qc = Qux;
 
// These two are equivalent:
qc.fa();
Foo::fa(&qc);
 
// This would not work because .gb() is ambiguous:
// qc.gb();
// But it's possible to disambiguate using UFCS
Foo::gb(&qc);
Bar::gb(&qc);
}
</source>