1
- use regex:: Regex ;
2
1
use std:: borrow:: Cow ;
3
2
use std:: cmp:: Ordering ;
4
3
use std:: fmt:: Debug ;
5
4
use std:: hash:: Hash ;
6
5
use std:: ops:: Deref ;
7
6
use std:: path:: { Path , PathBuf } ;
8
7
use std:: sync:: LazyLock ;
8
+
9
+ use arcstr:: ArcStr ;
10
+ use regex:: Regex ;
9
11
use thiserror:: Error ;
10
12
use url:: { ParseError , Url } ;
11
13
@@ -19,7 +21,7 @@ pub struct VerbatimUrl {
19
21
/// The parsed URL.
20
22
url : Url ,
21
23
/// The URL as it was provided by the user.
22
- given : Option < String > ,
24
+ given : Option < ArcStr > ,
23
25
}
24
26
25
27
impl Hash for VerbatimUrl {
@@ -112,9 +114,9 @@ impl VerbatimUrl {
112
114
113
115
/// Set the verbatim representation of the URL.
114
116
#[ must_use]
115
- pub fn with_given ( self , given : impl Into < String > ) -> Self {
117
+ pub fn with_given ( self , given : impl AsRef < str > ) -> Self {
116
118
Self {
117
- given : Some ( given. into ( ) ) ,
119
+ given : Some ( ArcStr :: from ( given. as_ref ( ) ) ) ,
118
120
..self
119
121
}
120
122
}
@@ -164,7 +166,7 @@ impl std::str::FromStr for VerbatimUrl {
164
166
type Err = VerbatimUrlError ;
165
167
166
168
fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
167
- Ok ( Self :: parse_url ( s) . map ( |url| url. with_given ( s. to_owned ( ) ) ) ?)
169
+ Ok ( Self :: parse_url ( s) . map ( |url| url. with_given ( s) ) ?)
168
170
}
169
171
}
170
172
@@ -232,21 +234,21 @@ impl Pep508Url for VerbatimUrl {
232
234
let path = normalize_url_path ( path) ;
233
235
234
236
if let Some ( working_dir) = working_dir {
235
- return Ok ( VerbatimUrl :: from_path ( path. as_ref ( ) , working_dir) ?
236
- . with_given ( url. to_string ( ) ) ) ;
237
+ return Ok (
238
+ VerbatimUrl :: from_path ( path. as_ref ( ) , working_dir) ?. with_given ( url)
239
+ ) ;
237
240
}
238
241
239
- Ok ( VerbatimUrl :: from_absolute_path ( path. as_ref ( ) ) ?
240
- . with_given ( url. to_string ( ) ) )
242
+ Ok ( VerbatimUrl :: from_absolute_path ( path. as_ref ( ) ) ?. with_given ( url) )
241
243
}
242
244
#[ cfg( not( feature = "non-pep508-extensions" ) ) ]
243
- Ok ( VerbatimUrl :: parse_url ( expanded) ?. with_given ( url. to_string ( ) ) )
245
+ Ok ( VerbatimUrl :: parse_url ( expanded) ?. with_given ( url) )
244
246
}
245
247
246
248
// Ex) `https://download.pytorch.org/whl/torch_stable.html`
247
249
Some ( _) => {
248
250
// Ex) `https://download.pytorch.org/whl/torch_stable.html`
249
- Ok ( VerbatimUrl :: parse_url ( expanded. as_ref ( ) ) ?. with_given ( url. to_string ( ) ) )
251
+ Ok ( VerbatimUrl :: parse_url ( expanded. as_ref ( ) ) ?. with_given ( url) )
250
252
}
251
253
252
254
// Ex) `C:\Users\ferris\wheel-0.42.0.tar.gz`
@@ -255,11 +257,10 @@ impl Pep508Url for VerbatimUrl {
255
257
{
256
258
if let Some ( working_dir) = working_dir {
257
259
return Ok ( VerbatimUrl :: from_path ( expanded. as_ref ( ) , working_dir) ?
258
- . with_given ( url. to_string ( ) ) ) ;
260
+ . with_given ( url) ) ;
259
261
}
260
262
261
- Ok ( VerbatimUrl :: from_absolute_path ( expanded. as_ref ( ) ) ?
262
- . with_given ( url. to_string ( ) ) )
263
+ Ok ( VerbatimUrl :: from_absolute_path ( expanded. as_ref ( ) ) ?. with_given ( url) )
263
264
}
264
265
#[ cfg( not( feature = "non-pep508-extensions" ) ) ]
265
266
Err ( Self :: Err :: NotAUrl ( expanded. to_string ( ) ) )
@@ -270,11 +271,12 @@ impl Pep508Url for VerbatimUrl {
270
271
#[ cfg( feature = "non-pep508-extensions" ) ]
271
272
{
272
273
if let Some ( working_dir) = working_dir {
273
- return Ok ( VerbatimUrl :: from_path ( expanded. as_ref ( ) , working_dir) ?
274
- . with_given ( url. to_string ( ) ) ) ;
274
+ return Ok (
275
+ VerbatimUrl :: from_path ( expanded. as_ref ( ) , working_dir) ?. with_given ( url)
276
+ ) ;
275
277
}
276
278
277
- Ok ( VerbatimUrl :: from_absolute_path ( expanded. as_ref ( ) ) ?. with_given ( url. to_string ( ) ) )
279
+ Ok ( VerbatimUrl :: from_absolute_path ( expanded. as_ref ( ) ) ?. with_given ( url) )
278
280
}
279
281
280
282
#[ cfg( not( feature = "non-pep508-extensions" ) ) ]
0 commit comments