@@ -73,6 +73,14 @@ assert!(data_url.fragment() == Some(""));
73
73
# run().unwrap();
74
74
```
75
75
76
+ ## Default Features
77
+
78
+ Versions `< 3` of the crate have no default features. Versions `>= 3` have the default feature 'std'.
79
+ If you are upgrading across this boundary and you have specified `default-features = false`, then
80
+ you will need to add the 'std' feature or the 'alloc' feature to your dependency.
81
+ The 'std' feature has the same behavior as the previous versions. The 'alloc' feature
82
+ provides no_std support.
83
+
76
84
## Serde
77
85
78
86
Enable the `serde` feature to include `Deserialize` and `Serialize` implementations for `url::Url`.
@@ -140,18 +148,6 @@ url = { version = "2", features = ["debugger_visualizer"] }
140
148
feature = "debugger_visualizer" ,
141
149
debugger_visualizer( natvis_file = "../../debug_metadata/url.natvis" )
142
150
) ]
143
- #![ cfg_attr(
144
- all(
145
- not( feature = "std" ) ,
146
- not( feature = "no_std_net" ) ,
147
- feature = "unstable"
148
- ) ,
149
- feature( ip_in_core)
150
- ) ]
151
- #![ cfg_attr(
152
- all( not( feature = "std" ) , feature = "unstable" ) ,
153
- feature( error_in_core)
154
- ) ]
155
151
156
152
pub use form_urlencoded;
157
153
@@ -165,11 +161,6 @@ extern crate alloc;
165
161
#[ cfg( not( feature = "alloc" ) ) ]
166
162
compile_error ! ( "the `alloc` feature must be enabled" ) ;
167
163
168
- #[ cfg( not( any( feature = "no_std_net" , feature = "std" , feature = "unstable" ) ) ) ]
169
- compile_error ! (
170
- "Either the `no_std_net`, `std` or, on nightly, the `unstable` feature, must be enabled"
171
- ) ;
172
-
173
164
#[ cfg( feature = "serde" ) ]
174
165
extern crate serde;
175
166
@@ -180,13 +171,11 @@ use crate::parser::{
180
171
} ;
181
172
use percent_encoding:: utf8_percent_encode;
182
173
use core:: borrow:: Borrow ;
183
- use core:: cmp;
184
- use core:: fmt:: { self , Write } ;
185
- use core:: hash;
174
+ use core:: fmt:: Write ;
186
175
#[ cfg( feature = "std" ) ]
187
176
#[ cfg( any( unix, windows, target_os = "redox" , target_os = "wasi" ) ) ]
188
177
use std:: io;
189
- use core:: mem;
178
+ use core:: { cmp , fmt , hash , mem} ;
190
179
use crate :: net:: IpAddr ;
191
180
#[ cfg( feature = "std" ) ]
192
181
#[ cfg( any( unix, windows, target_os = "redox" , target_os = "wasi" ) ) ]
@@ -196,7 +185,7 @@ use alloc::str;
196
185
use alloc:: string:: { String , ToString } ;
197
186
use alloc:: borrow:: ToOwned ;
198
187
#[ cfg( feature = "std" ) ]
199
- use std:: path:: { Path , PathBuf } ;
188
+ use std:: path:: PathBuf ;
200
189
use core:: convert:: TryFrom ;
201
190
202
191
/// `std` version of `net`
@@ -2564,7 +2553,7 @@ impl Url {
2564
2553
any( unix, windows, target_os = "redox" , target_os = "wasi" )
2565
2554
) ) ]
2566
2555
#[ allow( clippy:: result_unit_err) ]
2567
- pub fn from_file_path < P : AsRef < Path > > ( path : P ) -> Result < Url , ( ) > {
2556
+ pub fn from_file_path < P : AsRef < std :: path :: Path > > ( path : P ) -> Result < Url , ( ) > {
2568
2557
let mut serialization = "file://" . to_owned ( ) ;
2569
2558
let host_start = serialization. len ( ) as u32 ;
2570
2559
let ( host_end, host) = path_to_file_url_segments ( path. as_ref ( ) , & mut serialization) ?;
@@ -2606,7 +2595,7 @@ impl Url {
2606
2595
any( unix, windows, target_os = "redox" , target_os = "wasi" )
2607
2596
) ) ]
2608
2597
#[ allow( clippy:: result_unit_err) ]
2609
- pub fn from_directory_path < P : AsRef < Path > > ( path : P ) -> Result < Url , ( ) > {
2598
+ pub fn from_directory_path < P : AsRef < std :: path :: Path > > ( path : P ) -> Result < Url , ( ) > {
2610
2599
let mut url = Url :: from_file_path ( path) ?;
2611
2600
if !url. serialization . ends_with ( '/' ) {
2612
2601
url. serialization . push ( '/' )
@@ -2728,7 +2717,7 @@ impl Url {
2728
2717
any( unix, windows, target_os = "redox" , target_os = "wasi" )
2729
2718
) ) ]
2730
2719
#[ allow( clippy:: result_unit_err) ]
2731
- pub fn to_file_path ( & self ) -> Result < PathBuf , ( ) > {
2720
+ pub fn to_file_path ( & self ) -> Result < std :: path :: PathBuf , ( ) > {
2732
2721
if let Some ( segments) = self . path_segments ( ) {
2733
2722
let host = match self . host ( ) {
2734
2723
None | Some ( Host :: Domain ( "localhost" ) ) => None ,
@@ -2932,9 +2921,10 @@ impl<'de> serde::Deserialize<'de> for Url {
2932
2921
2933
2922
#[ cfg( all( feature = "std" , any( unix, target_os = "redox" , target_os = "wasi" ) ) ) ]
2934
2923
fn path_to_file_url_segments (
2935
- path : & Path ,
2924
+ path : & std :: path :: Path ,
2936
2925
serialization : & mut String ,
2937
2926
) -> Result < ( u32 , HostInternal ) , ( ) > {
2927
+ use parser:: SPECIAL_PATH_SEGMENT ;
2938
2928
use percent_encoding:: percent_encode;
2939
2929
#[ cfg( any( unix, target_os = "redox" ) ) ]
2940
2930
use std:: os:: unix:: prelude:: OsStrExt ;
@@ -2963,7 +2953,7 @@ fn path_to_file_url_segments(
2963
2953
2964
2954
#[ cfg( all( feature = "std" , windows) ) ]
2965
2955
fn path_to_file_url_segments (
2966
- path : & Path ,
2956
+ path : & std :: path :: Path ,
2967
2957
serialization : & mut String ,
2968
2958
) -> Result < ( u32 , HostInternal ) , ( ) > {
2969
2959
path_to_file_url_segments_windows ( path, serialization)
@@ -2972,8 +2962,9 @@ fn path_to_file_url_segments(
2972
2962
#[ cfg( feature = "std" ) ]
2973
2963
// Build this unconditionally to alleviate https://github.com/servo/rust-url/issues/102
2974
2964
#[ cfg_attr( not( windows) , allow( dead_code) ) ]
2965
+ #[ cfg( feature = "std" ) ]
2975
2966
fn path_to_file_url_segments_windows (
2976
- path : & Path ,
2967
+ path : & std :: path :: Path ,
2977
2968
serialization : & mut String ,
2978
2969
) -> Result < ( u32 , HostInternal ) , ( ) > {
2979
2970
use crate :: parser:: PATH_SEGMENT ;
@@ -3048,6 +3039,7 @@ fn file_url_segments_to_pathbuf(
3048
3039
use std:: os:: unix:: prelude:: OsStrExt ;
3049
3040
#[ cfg( target_os = "wasi" ) ]
3050
3041
use std:: os:: wasi:: prelude:: OsStrExt ;
3042
+ use std:: path:: PathBuf ;
3051
3043
3052
3044
if host. is_some ( ) {
3053
3045
return Err ( ( ) ) ;
@@ -3087,13 +3079,14 @@ fn file_url_segments_to_pathbuf(
3087
3079
fn file_url_segments_to_pathbuf (
3088
3080
host : Option < & str > ,
3089
3081
segments : str:: Split < char > ,
3090
- ) -> Result < PathBuf , ( ) > {
3082
+ ) -> Result < std :: path :: PathBuf , ( ) > {
3091
3083
file_url_segments_to_pathbuf_windows ( host, segments)
3092
3084
}
3093
3085
3094
3086
#[ cfg( feature = "std" ) ]
3095
3087
// Build this unconditionally to alleviate https://github.com/servo/rust-url/issues/102
3096
3088
#[ cfg_attr( not( windows) , allow( dead_code) ) ]
3089
+ #[ cfg( feature = "std" ) ]
3097
3090
fn file_url_segments_to_pathbuf_windows (
3098
3091
host : Option < & str > ,
3099
3092
mut segments : str:: Split < ' _ , char > ,
@@ -3138,7 +3131,7 @@ fn file_url_segments_to_pathbuf_windows(
3138
3131
Err ( ..) => return Err ( ( ) ) ,
3139
3132
}
3140
3133
}
3141
- let path = PathBuf :: from ( string) ;
3134
+ let path = std :: path :: PathBuf :: from ( string) ;
3142
3135
debug_assert ! (
3143
3136
path. is_absolute( ) ,
3144
3137
"to_file_path() failed to produce an absolute Path"
0 commit comments