diff options
| author | Volker Mische <volker.mische@gmail.com> | 2015-01-16 21:29:43 +0100 |
|---|---|---|
| committer | Steve Klabnik <steve@steveklabnik.com> | 2015-01-17 10:51:07 -0500 |
| commit | f12e60a5c8bacd8fb43b503000c19187aa3b09c2 (patch) | |
| tree | a9701ca2ea5d9769c8cbb005c42cce73f655e1dc /src | |
| parent | 0109ceaf827461d525ada1a71dcba909071d7cdc (diff) | |
| download | rust-f12e60a5c8bacd8fb43b503000c19187aa3b09c2.tar.gz rust-f12e60a5c8bacd8fb43b503000c19187aa3b09c2.zip | |
Make Index trait example clearer
The example of the `Index` and `IndexMut` trait contained too much `Foo`. It now contains a bit more `Bar` to make things clearer which parts are defining the type of the index.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/ops.rs | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index e7eb307689f..7d41c3fc5a5 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -830,28 +830,27 @@ shr_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize } /// /// # Example /// -/// A trivial implementation of `Index`. When `Foo[Foo]` happens, it ends up +/// A trivial implementation of `Index`. When `Foo[Bar]` happens, it ends up /// calling `index`, and therefore, `main` prints `Indexing!`. /// /// ``` -/// #![feature(associated_types)] -/// /// use std::ops::Index; /// /// #[derive(Copy)] /// struct Foo; +/// struct Bar; /// -/// impl Index<Foo> for Foo { +/// impl Index<Bar> for Foo { /// type Output = Foo; /// -/// fn index<'a>(&'a self, _index: &Foo) -> &'a Foo { +/// fn index<'a>(&'a self, _index: &Bar) -> &'a Foo { /// println!("Indexing!"); /// self /// } /// } /// /// fn main() { -/// Foo[Foo]; +/// Foo[Bar]; /// } /// ``` #[lang="index"] @@ -867,28 +866,27 @@ pub trait Index<Index: ?Sized> { /// /// # Example /// -/// A trivial implementation of `IndexMut`. When `Foo[Foo]` happens, it ends up +/// A trivial implementation of `IndexMut`. When `Foo[Bar]` happens, it ends up /// calling `index_mut`, and therefore, `main` prints `Indexing!`. /// /// ``` -/// #![feature(associated_types)] -/// /// use std::ops::IndexMut; /// /// #[derive(Copy)] /// struct Foo; +/// struct Bar; /// -/// impl IndexMut<Foo> for Foo { +/// impl IndexMut<Bar> for Foo { /// type Output = Foo; /// -/// fn index_mut<'a>(&'a mut self, _index: &Foo) -> &'a mut Foo { +/// fn index_mut<'a>(&'a mut self, _index: &Bar) -> &'a mut Foo { /// println!("Indexing!"); /// self /// } /// } /// /// fn main() { -/// &mut Foo[Foo]; +/// &mut Foo[Bar]; /// } /// ``` #[lang="index_mut"] |
