@@ -638,7 +638,7 @@ shr_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64)
638638 * ```
639639 */
640640#[ lang="index" ]
641- pub trait Index < Index , Result > {
641+ pub trait Index < Index , Result > {
642642 /// The method for the indexing (`Foo[Bar]`) operation
643643 fn index < ' a > ( & ' a self , index : & Index ) -> & ' a Result ;
644644}
@@ -651,7 +651,7 @@ pub trait Index<Index,Result> {
651651 * # Example
652652 *
653653 * A trivial implementation of `IndexMut`. When `Foo[Foo]` happens, it ends up
654- * calling `index `, and therefore, `main` prints `Indexing!`.
654+ * calling `index_mut `, and therefore, `main` prints `Indexing!`.
655655 *
656656 * ```
657657 * struct Foo;
@@ -669,11 +669,110 @@ pub trait Index<Index,Result> {
669669 * ```
670670 */
671671#[ lang="index_mut" ]
672- pub trait IndexMut < Index , Result > {
672+ pub trait IndexMut < Index , Result > {
673673 /// The method for the indexing (`Foo[Bar]`) operation
674674 fn index_mut < ' a > ( & ' a mut self , index : & Index ) -> & ' a mut Result ;
675675}
676676
677+ /**
678+ *
679+ * The `Slice` trait is used to specify the functionality of slicing operations
680+ * like `arr[from..to]` when used in an immutable context.
681+ *
682+ * # Example
683+ *
684+ * A trivial implementation of `Slice`. When `Foo[..Foo]` happens, it ends up
685+ * calling `slice_to`, and therefore, `main` prints `Slicing!`.
686+ *
687+ * ```
688+ * struct Foo;
689+ *
690+ * impl ::core::ops::Slice<Foo, Foo> for Foo {
691+ * fn as_slice_<'a>(&'a self) -> &'a Foo {
692+ * println!("Slicing!");
693+ * self
694+ * }
695+ * fn slice_from_<'a>(&'a self, from: &Foo) -> &'a Foo {
696+ * println!("Slicing!");
697+ * self
698+ * }
699+ * fn slice_to_<'a>(&'a self, to: &Foo) -> &'a Foo {
700+ * println!("Slicing!");
701+ * self
702+ * }
703+ * fn slice_<'a>(&'a self, from: &Foo, to: &Foo) -> &'a Foo {
704+ * println!("Slicing!");
705+ * self
706+ * }
707+ * }
708+ *
709+ * fn main() {
710+ * Foo[..Foo];
711+ * }
712+ * ```
713+ */
714+ // FIXME(#17273) remove the postscript _s
715+ #[ lang="slice" ]
716+ pub trait Slice < Idx , Sized ? Result > for Sized ? {
717+ /// The method for the slicing operation foo[]
718+ fn as_slice_ < ' a > ( & ' a self ) -> & ' a Result ;
719+ /// The method for the slicing operation foo[from..]
720+ fn slice_from_ < ' a > ( & ' a self , from : & Idx ) -> & ' a Result ;
721+ /// The method for the slicing operation foo[..to]
722+ fn slice_to_ < ' a > ( & ' a self , to : & Idx ) -> & ' a Result ;
723+ /// The method for the slicing operation foo[from..to]
724+ fn slice_ < ' a > ( & ' a self , from : & Idx , to : & Idx ) -> & ' a Result ;
725+ }
726+
727+ /**
728+ *
729+ * The `SliceMut` trait is used to specify the functionality of slicing
730+ * operations like `arr[from..to]`, when used in a mutable context.
731+ *
732+ * # Example
733+ *
734+ * A trivial implementation of `SliceMut`. When `Foo[Foo..]` happens, it ends up
735+ * calling `slice_from_mut`, and therefore, `main` prints `Slicing!`.
736+ *
737+ * ```
738+ * struct Foo;
739+ *
740+ * impl ::core::ops::SliceMut<Foo, Foo> for Foo {
741+ * fn as_mut_slice_<'a>(&'a mut self) -> &'a mut Foo {
742+ * println!("Slicing!");
743+ * self
744+ * }
745+ * fn slice_from_mut_<'a>(&'a mut self, from: &Foo) -> &'a mut Foo {
746+ * println!("Slicing!");
747+ * self
748+ * }
749+ * fn slice_to_mut_<'a>(&'a mut self, to: &Foo) -> &'a mut Foo {
750+ * println!("Slicing!");
751+ * self
752+ * }
753+ * fn slice_mut_<'a>(&'a mut self, from: &Foo, to: &Foo) -> &'a mut Foo {
754+ * println!("Slicing!");
755+ * self
756+ * }
757+ * }
758+ *
759+ * fn main() {
760+ * Foo[mut Foo..];
761+ * }
762+ * ```
763+ */
764+ // FIXME(#17273) remove the postscript _s
765+ #[ lang="slice_mut" ]
766+ pub trait SliceMut < Idx , Sized ? Result > for Sized ? {
767+ /// The method for the slicing operation foo[]
768+ fn as_mut_slice_ < ' a > ( & ' a mut self ) -> & ' a mut Result ;
769+ /// The method for the slicing operation foo[from..]
770+ fn slice_from_mut_ < ' a > ( & ' a mut self , from : & Idx ) -> & ' a mut Result ;
771+ /// The method for the slicing operation foo[..to]
772+ fn slice_to_mut_ < ' a > ( & ' a mut self , to : & Idx ) -> & ' a mut Result ;
773+ /// The method for the slicing operation foo[from..to]
774+ fn slice_mut_ < ' a > ( & ' a mut self , from : & Idx , to : & Idx ) -> & ' a mut Result ;
775+ }
677776/**
678777 *
679778 * The `Deref` trait is used to specify the functionality of dereferencing
0 commit comments