@@ -9,26 +9,15 @@ use num_traits::{cast::ToPrimitive, sign::Signed};
9
9
use std:: str:: FromStr ;
10
10
11
11
#[ 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 > > {
18
13
#[ pyarg( any, default ) ]
19
14
sep : Option < T > ,
20
15
#[ pyarg( any, default = "-1" ) ]
21
16
maxsplit : isize ,
22
- _phantom1 : std:: marker:: PhantomData < & ' a S > ,
23
- _phantom2 : std:: marker:: PhantomData < E > ,
17
+ _phantom : std:: marker:: PhantomData < & ' s ( ) > ,
24
18
}
25
19
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 > {
32
21
pub fn get_value ( self , vm : & VirtualMachine ) -> PyResult < ( Option < T > , isize ) > {
33
22
let sep = if let Some ( s) = self . sep {
34
23
let sep = s. as_ref ( ) ;
@@ -124,11 +113,9 @@ impl StringRange for std::ops::Range<usize> {
124
113
}
125
114
}
126
115
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 ;
132
119
}
133
120
134
121
pub trait AnyStrContainer < S >
@@ -140,28 +127,23 @@ where
140
127
fn push_str ( & mut self , s : & S ) ;
141
128
}
142
129
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 ;
154
136
155
- fn element_bytes_len ( c : E ) -> usize ;
137
+ fn element_bytes_len ( c : Self :: Char ) -> usize ;
156
138
157
139
fn to_container ( & self ) -> Self :: Container ;
158
140
fn as_bytes ( & self ) -> & [ u8 ] ;
159
141
fn as_utf8_str ( & self ) -> Result < & str , std:: str:: Utf8Error > ;
160
142
fn chars ( & ' s self ) -> Self :: CharIter ;
161
143
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 ;
163
145
// 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 ;
165
147
fn bytes_len ( & self ) -> usize ;
166
148
// fn chars_len(&self) -> usize; // cannot access to cache here
167
149
fn is_empty ( & self ) -> bool ;
@@ -175,14 +157,14 @@ where
175
157
176
158
fn py_split < T , SP , SN , SW , R > (
177
159
& self ,
178
- args : SplitArgs < ' s , T , Self , E > ,
160
+ args : SplitArgs < ' s , T > ,
179
161
vm : & VirtualMachine ,
180
162
split : SP ,
181
163
splitn : SN ,
182
164
splitw : SW ,
183
165
) -> PyResult < Vec < R > >
184
166
where
185
- T : TryFromObject + AnyStrWrapper < Self > ,
167
+ T : TryFromObject + AnyStrWrapper < ' s , Str = Self > ,
186
168
SP : Fn ( & Self , & Self , & VirtualMachine ) -> Vec < R > ,
187
169
SN : Fn ( & Self , & Self , usize , & VirtualMachine ) -> Vec < R > ,
188
170
SW : Fn ( & Self , isize , & VirtualMachine ) -> Vec < R > ,
@@ -249,7 +231,7 @@ where
249
231
func_default : FD ,
250
232
) -> & ' a Self
251
233
where
252
- S : AnyStrWrapper < Self > ,
234
+ S : AnyStrWrapper < ' s , Str = Self > ,
253
235
FC : Fn ( & ' a Self , & Self ) -> & ' a Self ,
254
236
FD : Fn ( & ' a Self ) -> & ' a Self ,
255
237
{
@@ -286,7 +268,7 @@ where
286
268
}
287
269
}
288
270
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 {
290
272
let mut u = Self :: Container :: with_capacity (
291
273
( left + right) * Self :: element_bytes_len ( fillchar) + self . bytes_len ( ) ,
292
274
) ;
@@ -296,23 +278,23 @@ where
296
278
u
297
279
}
298
280
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 {
300
282
let marg = width - len;
301
283
let left = marg / 2 + ( marg & width & 1 ) ;
302
284
self . py_pad ( left, marg - left, fillchar)
303
285
}
304
286
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 {
306
288
self . py_pad ( 0 , width - len, fillchar)
307
289
}
308
290
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 {
310
292
self . py_pad ( width - len, 0 , fillchar)
311
293
}
312
294
313
295
fn py_join < ' a > (
314
296
& self ,
315
- mut iter : PyIterator < ' a , impl AnyStrWrapper < Self > + TryFromObject > ,
297
+ mut iter : PyIterator < ' a , impl AnyStrWrapper < ' s , Str = Self > + TryFromObject > ,
316
298
) -> PyResult < Self :: Container > {
317
299
let mut joined = if let Some ( elem) = iter. next ( ) {
318
300
elem?. as_ref ( ) . to_container ( )
0 commit comments