@@ -149,7 +149,7 @@ impl<T: Ord + Clone + 'static> PreferredContainer for T {
149149}
150150
151151impl < T : Ord + Clone + ' static > PreferredContainer for [ T ] {
152- type Container = SliceContainer2 < T > ;
152+ type Container = SliceContainer < T > ;
153153}
154154
155155/// An update and layout description based on preferred containers.
@@ -320,7 +320,7 @@ impl BatchContainer for OffsetList {
320320 }
321321}
322322
323- pub use self :: containers:: { BatchContainer , SliceContainer , SliceContainer2 } ;
323+ pub use self :: containers:: { BatchContainer , SliceContainer } ;
324324
325325/// Containers for data that resemble `Vec<T>`, with leaner implementations.
326326pub mod containers {
@@ -559,132 +559,4 @@ pub mod containers {
559559 }
560560 }
561561 }
562-
563- /// A container that accepts slices `[B::Item]`.
564- pub struct SliceContainer2 < B > {
565- text : String ,
566- /// Offsets that bound each contained slice.
567- ///
568- /// The length will be one greater than the number of contained slices,
569- /// starting with zero and ending with `self.inner.len()`.
570- offsets : Vec < usize > ,
571- /// An inner container for sequences of `B` that dereferences to a slice.
572- inner : Vec < B > ,
573- }
574-
575- /// Welcome to GATs!
576- pub struct Greetings < ' a , B > {
577- /// Text that decorates the data.
578- pub text : Option < & ' a str > ,
579- /// The data itself.
580- pub slice : & ' a [ B ] ,
581- }
582-
583- impl < ' a , B > Copy for Greetings < ' a , B > { }
584- impl < ' a , B > Clone for Greetings < ' a , B > {
585- fn clone ( & self ) -> Self { * self }
586- }
587-
588- use std:: cmp:: Ordering ;
589- impl < ' a , ' b , B : Ord > PartialEq < Greetings < ' a , B > > for Greetings < ' b , B > {
590- fn eq ( & self , other : & Greetings < ' a , B > ) -> bool {
591- self . slice . eq ( other. slice )
592- }
593- }
594- impl < ' a , B : Ord > Eq for Greetings < ' a , B > { }
595- impl < ' a , ' b , B : Ord > PartialOrd < Greetings < ' a , B > > for Greetings < ' b , B > {
596- fn partial_cmp ( & self , other : & Greetings < ' a , B > ) -> Option < Ordering > {
597- self . slice . partial_cmp ( other. slice )
598- }
599- }
600- impl < ' a , B : Ord > Ord for Greetings < ' a , B > {
601- fn cmp ( & self , other : & Self ) -> Ordering {
602- self . partial_cmp ( other) . unwrap ( )
603- }
604- }
605-
606- impl < ' a , B : Ord + Clone > MyTrait < ' a > for Greetings < ' a , B > {
607- type Owned = Vec < B > ;
608- fn into_owned ( self ) -> Self :: Owned { self . slice . to_vec ( ) }
609- fn clone_onto ( & self , other : & mut Self :: Owned ) {
610- self . slice . clone_into ( other) ;
611- }
612- fn compare ( & self , other : & Self :: Owned ) -> std:: cmp:: Ordering {
613- self . slice . cmp ( & other[ ..] )
614- }
615- fn borrow_as ( other : & ' a Self :: Owned ) -> Self {
616- Self {
617- text : None ,
618- slice : & other[ ..] ,
619- }
620- }
621- }
622-
623- impl < B > BatchContainer for SliceContainer2 < B >
624- where
625- B : Ord + Clone + Sized + ' static ,
626- {
627- type PushItem = Vec < B > ;
628- type ReadItem < ' a > = Greetings < ' a , B > ;
629- fn push ( & mut self , item : Vec < B > ) {
630- for x in item. into_iter ( ) {
631- self . inner . push ( x) ;
632- }
633- self . offsets . push ( self . inner . len ( ) ) ;
634- }
635- fn copy_push ( & mut self , item : & Vec < B > ) {
636- self . copy ( <_ as MyTrait >:: borrow_as ( item) ) ;
637- }
638- fn copy ( & mut self , item : Self :: ReadItem < ' _ > ) {
639- for x in item. slice . iter ( ) {
640- self . inner . copy ( x) ;
641- }
642- self . offsets . push ( self . inner . len ( ) ) ;
643- }
644- fn copy_range ( & mut self , other : & Self , start : usize , end : usize ) {
645- for index in start .. end {
646- self . copy ( other. index ( index) ) ;
647- }
648- }
649- fn with_capacity ( size : usize ) -> Self {
650- let mut offsets = Vec :: with_capacity ( size + 1 ) ;
651- offsets. push ( 0 ) ;
652- Self {
653- text : format ! ( "Hello!" ) ,
654- offsets,
655- inner : Vec :: with_capacity ( size) ,
656- }
657- }
658- fn merge_capacity ( cont1 : & Self , cont2 : & Self ) -> Self {
659- let mut offsets = Vec :: with_capacity ( cont1. inner . len ( ) + cont2. inner . len ( ) + 1 ) ;
660- offsets. push ( 0 ) ;
661- Self {
662- text : format ! ( "Hello!" ) ,
663- offsets,
664- inner : Vec :: with_capacity ( cont1. inner . len ( ) + cont2. inner . len ( ) ) ,
665- }
666- }
667- fn index ( & self , index : usize ) -> Self :: ReadItem < ' _ > {
668- let lower = self . offsets [ index] ;
669- let upper = self . offsets [ index+1 ] ;
670- Greetings {
671- text : Some ( & self . text ) ,
672- slice : & self . inner [ lower .. upper] ,
673- }
674- }
675- fn len ( & self ) -> usize {
676- self . offsets . len ( ) - 1
677- }
678- }
679-
680- /// Default implementation introduces a first offset.
681- impl < B > Default for SliceContainer2 < B > {
682- fn default ( ) -> Self {
683- Self {
684- text : format ! ( "Hello!" ) ,
685- offsets : vec ! [ 0 ] ,
686- inner : Default :: default ( ) ,
687- }
688- }
689- }
690562}
0 commit comments