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.
13 #![feature(slicing_syntax)]
16 use core::ops::{Slice,SliceMut};
18 static mut COUNT: uint = 0;
22 impl Slice<Foo, Foo> for Foo {
23 fn as_slice_<'a>(&'a self) -> &'a Foo {
24 unsafe { COUNT += 1; }
27 fn slice_from_or_fail<'a>(&'a self, _from: &Foo) -> &'a Foo {
28 unsafe { COUNT += 1; }
31 fn slice_to_or_fail<'a>(&'a self, _to: &Foo) -> &'a Foo {
32 unsafe { COUNT += 1; }
35 fn slice_or_fail<'a>(&'a self, _from: &Foo, _to: &Foo) -> &'a Foo {
36 unsafe { COUNT += 1; }
41 impl SliceMut<Foo, Foo> for Foo {
42 fn as_mut_slice_<'a>(&'a mut self) -> &'a mut Foo {
43 unsafe { COUNT += 1; }
46 fn slice_from_or_fail_mut<'a>(&'a mut self, _from: &Foo) -> &'a mut Foo {
47 unsafe { COUNT += 1; }
50 fn slice_to_or_fail_mut<'a>(&'a mut self, _to: &Foo) -> &'a mut Foo {
51 unsafe { COUNT += 1; }
54 fn slice_or_fail_mut<'a>(&'a mut self, _from: &Foo, _to: &Foo) -> &'a mut Foo {
55 unsafe { COUNT += 1; }