@@ -9,26 +9,15 @@ use num_traits::{cast::ToPrimitive, sign::Signed};
99use std:: str:: FromStr ;
1010
1111#[ derive( FromArgs ) ]
12- pub struct SplitArgs < ' a , T , S , E >
13- where
14- T : TryFromObject + AnyStrWrapper < S > ,
15- S : ?Sized + AnyStr < ' a , E > ,
16- E : Copy ,
17- {
12+ pub struct SplitArgs < ' s , T : TryFromObject + AnyStrWrapper < ' s > > {
1813 #[ pyarg( any, default ) ]
1914 sep : Option < T > ,
2015 #[ pyarg( any, default = "-1" ) ]
2116 maxsplit : isize ,
22- _phantom1 : std:: marker:: PhantomData < & ' a S > ,
23- _phantom2 : std:: marker:: PhantomData < E > ,
17+ _phantom : std:: marker:: PhantomData < & ' s ( ) > ,
2418}
2519
26- impl < ' a , T , S , E > SplitArgs < ' a , T , S , E >
27- where
28- T : TryFromObject + AnyStrWrapper < S > ,
29- S : ?Sized + AnyStr < ' a , E > ,
30- E : Copy ,
31- {
20+ impl < ' s , T : TryFromObject + AnyStrWrapper < ' s > > SplitArgs < ' s , T > {
3221 pub fn get_value ( self , vm : & VirtualMachine ) -> PyResult < ( Option < T > , isize ) > {
3322 let sep = if let Some ( s) = self . sep {
3423 let sep = s. as_ref ( ) ;
@@ -124,11 +113,9 @@ impl StringRange for std::ops::Range<usize> {
124113 }
125114}
126115
127- pub trait AnyStrWrapper < S >
128- where
129- S : ?Sized ,
130- {
131- fn as_ref ( & self ) -> & S ;
116+ pub trait AnyStrWrapper < ' s > {
117+ type Str : ?Sized + AnyStr < ' s > ;
118+ fn as_ref ( & self ) -> & Self :: Str ;
132119}
133120
134121pub trait AnyStrContainer < S >
@@ -140,28 +127,23 @@ where
140127 fn push_str ( & mut self , s : & S ) ;
141128}
142129
143- pub trait AnyStr < ' s , E >
144- where
145- E : Copy ,
146- Self : ' s ,
147- Self :: Container : AnyStrContainer < Self > + std:: iter:: Extend < E > ,
148- Self :: CharIter : ' s + std:: iter:: Iterator < Item = char > ,
149- Self :: ElementIter : ' s + std:: iter:: Iterator < Item = E > ,
150- {
151- type Container ;
152- type CharIter ;
153- type ElementIter ;
130+ // TODO: GATs for `'s` once stabilized
131+ pub trait AnyStr < ' s > : ' s {
132+ type Char : Copy ;
133+ type Container : AnyStrContainer < Self > + Extend < Self :: Char > ;
134+ type CharIter : Iterator < Item = char > + ' s ;
135+ type ElementIter : Iterator < Item = Self :: Char > + ' s ;
154136
155- fn element_bytes_len ( c : E ) -> usize ;
137+ fn element_bytes_len ( c : Self :: Char ) -> usize ;
156138
157139 fn to_container ( & self ) -> Self :: Container ;
158140 fn as_bytes ( & self ) -> & [ u8 ] ;
159141 fn as_utf8_str ( & self ) -> Result < & str , std:: str:: Utf8Error > ;
160142 fn chars ( & ' s self ) -> Self :: CharIter ;
161143 fn elements ( & ' s self ) -> Self :: ElementIter ;
162- fn get_bytes < ' a > ( & ' a self , range : std:: ops:: Range < usize > ) -> & ' a Self ;
144+ fn get_bytes ( & self , range : std:: ops:: Range < usize > ) -> & Self ;
163145 // FIXME: get_chars is expensive for str
164- fn get_chars < ' a > ( & ' a self , range : std:: ops:: Range < usize > ) -> & ' a Self ;
146+ fn get_chars ( & self , range : std:: ops:: Range < usize > ) -> & Self ;
165147 fn bytes_len ( & self ) -> usize ;
166148 // fn chars_len(&self) -> usize; // cannot access to cache here
167149 fn is_empty ( & self ) -> bool ;
@@ -175,14 +157,14 @@ where
175157
176158 fn py_split < T , SP , SN , SW , R > (
177159 & self ,
178- args : SplitArgs < ' s , T , Self , E > ,
160+ args : SplitArgs < ' s , T > ,
179161 vm : & VirtualMachine ,
180162 split : SP ,
181163 splitn : SN ,
182164 splitw : SW ,
183165 ) -> PyResult < Vec < R > >
184166 where
185- T : TryFromObject + AnyStrWrapper < Self > ,
167+ T : TryFromObject + AnyStrWrapper < ' s , Str = Self > ,
186168 SP : Fn ( & Self , & Self , & VirtualMachine ) -> Vec < R > ,
187169 SN : Fn ( & Self , & Self , usize , & VirtualMachine ) -> Vec < R > ,
188170 SW : Fn ( & Self , isize , & VirtualMachine ) -> Vec < R > ,
@@ -249,7 +231,7 @@ where
249231 func_default : FD ,
250232 ) -> & ' a Self
251233 where
252- S : AnyStrWrapper < Self > ,
234+ S : AnyStrWrapper < ' s , Str = Self > ,
253235 FC : Fn ( & ' a Self , & Self ) -> & ' a Self ,
254236 FD : Fn ( & ' a Self ) -> & ' a Self ,
255237 {
@@ -286,7 +268,7 @@ where
286268 }
287269 }
288270
289- fn py_pad ( & self , left : usize , right : usize , fillchar : E ) -> Self :: Container {
271+ fn py_pad ( & self , left : usize , right : usize , fillchar : Self :: Char ) -> Self :: Container {
290272 let mut u = Self :: Container :: with_capacity (
291273 ( left + right) * Self :: element_bytes_len ( fillchar) + self . bytes_len ( ) ,
292274 ) ;
@@ -296,23 +278,23 @@ where
296278 u
297279 }
298280
299- fn py_center ( & self , width : usize , fillchar : E , len : usize ) -> Self :: Container {
281+ fn py_center ( & self , width : usize , fillchar : Self :: Char , len : usize ) -> Self :: Container {
300282 let marg = width - len;
301283 let left = marg / 2 + ( marg & width & 1 ) ;
302284 self . py_pad ( left, marg - left, fillchar)
303285 }
304286
305- fn py_ljust ( & self , width : usize , fillchar : E , len : usize ) -> Self :: Container {
287+ fn py_ljust ( & self , width : usize , fillchar : Self :: Char , len : usize ) -> Self :: Container {
306288 self . py_pad ( 0 , width - len, fillchar)
307289 }
308290
309- fn py_rjust ( & self , width : usize , fillchar : E , len : usize ) -> Self :: Container {
291+ fn py_rjust ( & self , width : usize , fillchar : Self :: Char , len : usize ) -> Self :: Container {
310292 self . py_pad ( width - len, 0 , fillchar)
311293 }
312294
313295 fn py_join < ' a > (
314296 & self ,
315- mut iter : PyIterator < ' a , impl AnyStrWrapper < Self > + TryFromObject > ,
297+ mut iter : PyIterator < ' a , impl AnyStrWrapper < ' s , Str = Self > + TryFromObject > ,
316298 ) -> PyResult < Self :: Container > {
317299 let mut joined = if let Some ( elem) = iter. next ( ) {
318300 elem?. as_ref ( ) . to_container ( )
0 commit comments