From 9e25a1ccd32b3dd3e02ba841174fd620651bfb67 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Mon, 16 Nov 2015 16:51:58 -0500 Subject: [PATCH] Improve UFCS example Fixes #29493 --- src/doc/trpl/ufcs.md | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/doc/trpl/ufcs.md b/src/doc/trpl/ufcs.md index 2353c63a606..7725970564b 100644 --- a/src/doc/trpl/ufcs.md +++ b/src/doc/trpl/ufcs.md @@ -109,19 +109,28 @@ Here’s an example of using the longer form. ```rust trait Foo { - fn clone(&self); + fn foo() -> i32; } -#[derive(Clone)] struct Bar; -impl Foo for Bar { - fn clone(&self) { - println!("Making a clone of Bar"); - - ::clone(self); +impl Bar { + fn foo() -> i32 { + 20 } } + +impl Foo for Bar { + fn foo() -> i32 { + 10 + } +} + +fn main() { + assert_eq!(10, ::foo()); + assert_eq!(20, Bar::foo()); +} ``` -This will call the `Clone` trait’s `clone()` method, rather than `Foo`’s. +Using the angle bracket syntax lets you call the trait method instead of the +inherent one.