1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Test slicing sugar.
14 use core::ops::{Index, IndexMut, Range, RangeTo, RangeFrom, RangeFull};
16 static mut COUNT: usize = 0;
20 impl Index<Range<Foo>> for Foo {
22 fn index(&self, index: Range<Foo>) -> &Foo {
23 unsafe { COUNT += 1; }
27 impl Index<RangeTo<Foo>> for Foo {
29 fn index(&self, index: RangeTo<Foo>) -> &Foo {
30 unsafe { COUNT += 1; }
34 impl Index<RangeFrom<Foo>> for Foo {
36 fn index(&self, index: RangeFrom<Foo>) -> &Foo {
37 unsafe { COUNT += 1; }
41 impl Index<RangeFull> for Foo {
43 fn index(&self, _index: RangeFull) -> &Foo {
44 unsafe { COUNT += 1; }
49 impl IndexMut<Range<Foo>> for Foo {
50 fn index_mut(&mut self, index: Range<Foo>) -> &mut Foo {
51 unsafe { COUNT += 1; }
55 impl IndexMut<RangeTo<Foo>> for Foo {
56 fn index_mut(&mut self, index: RangeTo<Foo>) -> &mut Foo {
57 unsafe { COUNT += 1; }
61 impl IndexMut<RangeFrom<Foo>> for Foo {
62 fn index_mut(&mut self, index: RangeFrom<Foo>) -> &mut Foo {
63 unsafe { COUNT += 1; }
67 impl IndexMut<RangeFull> for Foo {
68 fn index_mut(&mut self, _index: RangeFull) -> &mut Foo {
69 unsafe { COUNT += 1; }