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.
17 use core::ops::{Index, IndexMut, Range, RangeTo, RangeFrom, RangeFull};
19 static mut COUNT: usize = 0;
23 impl Index<Range<Foo>> for Foo {
25 fn index(&self, index: Range<Foo>) -> &Foo {
26 unsafe { COUNT += 1; }
30 impl Index<RangeTo<Foo>> for Foo {
32 fn index(&self, index: RangeTo<Foo>) -> &Foo {
33 unsafe { COUNT += 1; }
37 impl Index<RangeFrom<Foo>> for Foo {
39 fn index(&self, index: RangeFrom<Foo>) -> &Foo {
40 unsafe { COUNT += 1; }
44 impl Index<RangeFull> for Foo {
46 fn index(&self, _index: RangeFull) -> &Foo {
47 unsafe { COUNT += 1; }
52 impl IndexMut<Range<Foo>> for Foo {
53 fn index_mut(&mut self, index: Range<Foo>) -> &mut Foo {
54 unsafe { COUNT += 1; }
58 impl IndexMut<RangeTo<Foo>> for Foo {
59 fn index_mut(&mut self, index: RangeTo<Foo>) -> &mut Foo {
60 unsafe { COUNT += 1; }
64 impl IndexMut<RangeFrom<Foo>> for Foo {
65 fn index_mut(&mut self, index: RangeFrom<Foo>) -> &mut Foo {
66 unsafe { COUNT += 1; }
70 impl IndexMut<RangeFull> for Foo {
71 fn index_mut(&mut self, _index: RangeFull) -> &mut Foo {
72 unsafe { COUNT += 1; }