Skip to content

Commit f12e60a

Browse files
vmxsteveklabnik
authored andcommitted
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.
1 parent 0109cea commit f12e60a

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/libcore/ops.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -830,28 +830,27 @@ shr_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
830830
///
831831
/// # Example
832832
///
833-
/// A trivial implementation of `Index`. When `Foo[Foo]` happens, it ends up
833+
/// A trivial implementation of `Index`. When `Foo[Bar]` happens, it ends up
834834
/// calling `index`, and therefore, `main` prints `Indexing!`.
835835
///
836836
/// ```
837-
/// #![feature(associated_types)]
838-
///
839837
/// use std::ops::Index;
840838
///
841839
/// #[derive(Copy)]
842840
/// struct Foo;
841+
/// struct Bar;
843842
///
844-
/// impl Index<Foo> for Foo {
843+
/// impl Index<Bar> for Foo {
845844
/// type Output = Foo;
846845
///
847-
/// fn index<'a>(&'a self, _index: &Foo) -> &'a Foo {
846+
/// fn index<'a>(&'a self, _index: &Bar) -> &'a Foo {
848847
/// println!("Indexing!");
849848
/// self
850849
/// }
851850
/// }
852851
///
853852
/// fn main() {
854-
/// Foo[Foo];
853+
/// Foo[Bar];
855854
/// }
856855
/// ```
857856
#[lang="index"]
@@ -867,28 +866,27 @@ pub trait Index<Index: ?Sized> {
867866
///
868867
/// # Example
869868
///
870-
/// A trivial implementation of `IndexMut`. When `Foo[Foo]` happens, it ends up
869+
/// A trivial implementation of `IndexMut`. When `Foo[Bar]` happens, it ends up
871870
/// calling `index_mut`, and therefore, `main` prints `Indexing!`.
872871
///
873872
/// ```
874-
/// #![feature(associated_types)]
875-
///
876873
/// use std::ops::IndexMut;
877874
///
878875
/// #[derive(Copy)]
879876
/// struct Foo;
877+
/// struct Bar;
880878
///
881-
/// impl IndexMut<Foo> for Foo {
879+
/// impl IndexMut<Bar> for Foo {
882880
/// type Output = Foo;
883881
///
884-
/// fn index_mut<'a>(&'a mut self, _index: &Foo) -> &'a mut Foo {
882+
/// fn index_mut<'a>(&'a mut self, _index: &Bar) -> &'a mut Foo {
885883
/// println!("Indexing!");
886884
/// self
887885
/// }
888886
/// }
889887
///
890888
/// fn main() {
891-
/// &mut Foo[Foo];
889+
/// &mut Foo[Bar];
892890
/// }
893891
/// ```
894892
#[lang="index_mut"]

0 commit comments

Comments
 (0)