@@ -73,6 +73,14 @@ assert!(data_url.fragment() == Some(""));
7373# run().unwrap();
7474```
7575
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+
7684## Serde
7785
7886Enable the `serde` feature to include `Deserialize` and `Serialize` implementations for `url::Url`.
@@ -140,18 +148,6 @@ url = { version = "2", features = ["debugger_visualizer"] }
140148 feature = "debugger_visualizer" ,
141149 debugger_visualizer( natvis_file = "../../debug_metadata/url.natvis" )
142150) ]
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- ) ]
155151
156152pub use form_urlencoded;
157153
@@ -165,11 +161,6 @@ extern crate alloc;
165161#[ cfg( not( feature = "alloc" ) ) ]
166162compile_error ! ( "the `alloc` feature must be enabled" ) ;
167163
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-
173164#[ cfg( feature = "serde" ) ]
174165extern crate serde;
175166
@@ -180,13 +171,11 @@ use crate::parser::{
180171} ;
181172use percent_encoding:: utf8_percent_encode;
182173use core:: borrow:: Borrow ;
183- use core:: cmp;
184- use core:: fmt:: { self , Write } ;
185- use core:: hash;
174+ use core:: fmt:: Write ;
186175#[ cfg( feature = "std" ) ]
187176#[ cfg( any( unix, windows, target_os = "redox" , target_os = "wasi" ) ) ]
188177use std:: io;
189- use core:: mem;
178+ use core:: { cmp , fmt , hash , mem} ;
190179use crate :: net:: IpAddr ;
191180#[ cfg( feature = "std" ) ]
192181#[ cfg( any( unix, windows, target_os = "redox" , target_os = "wasi" ) ) ]
@@ -196,7 +185,7 @@ use alloc::str;
196185use alloc:: string:: { String , ToString } ;
197186use alloc:: borrow:: ToOwned ;
198187#[ cfg( feature = "std" ) ]
199- use std:: path:: { Path , PathBuf } ;
188+ use std:: path:: PathBuf ;
200189use core:: convert:: TryFrom ;
201190
202191/// `std` version of `net`
@@ -2564,7 +2553,7 @@ impl Url {
25642553 any( unix, windows, target_os = "redox" , target_os = "wasi" )
25652554 ) ) ]
25662555 #[ 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 , ( ) > {
25682557 let mut serialization = "file://" . to_owned ( ) ;
25692558 let host_start = serialization. len ( ) as u32 ;
25702559 let ( host_end, host) = path_to_file_url_segments ( path. as_ref ( ) , & mut serialization) ?;
@@ -2606,7 +2595,7 @@ impl Url {
26062595 any( unix, windows, target_os = "redox" , target_os = "wasi" )
26072596 ) ) ]
26082597 #[ 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 , ( ) > {
26102599 let mut url = Url :: from_file_path ( path) ?;
26112600 if !url. serialization . ends_with ( '/' ) {
26122601 url. serialization . push ( '/' )
@@ -2728,7 +2717,7 @@ impl Url {
27282717 any( unix, windows, target_os = "redox" , target_os = "wasi" )
27292718 ) ) ]
27302719 #[ 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 , ( ) > {
27322721 if let Some ( segments) = self . path_segments ( ) {
27332722 let host = match self . host ( ) {
27342723 None | Some ( Host :: Domain ( "localhost" ) ) => None ,
@@ -2932,9 +2921,10 @@ impl<'de> serde::Deserialize<'de> for Url {
29322921
29332922#[ cfg( all( feature = "std" , any( unix, target_os = "redox" , target_os = "wasi" ) ) ) ]
29342923fn path_to_file_url_segments (
2935- path : & Path ,
2924+ path : & std :: path :: Path ,
29362925 serialization : & mut String ,
29372926) -> Result < ( u32 , HostInternal ) , ( ) > {
2927+ use parser:: SPECIAL_PATH_SEGMENT ;
29382928 use percent_encoding:: percent_encode;
29392929 #[ cfg( any( unix, target_os = "redox" ) ) ]
29402930 use std:: os:: unix:: prelude:: OsStrExt ;
@@ -2963,7 +2953,7 @@ fn path_to_file_url_segments(
29632953
29642954#[ cfg( all( feature = "std" , windows) ) ]
29652955fn path_to_file_url_segments (
2966- path : & Path ,
2956+ path : & std :: path :: Path ,
29672957 serialization : & mut String ,
29682958) -> Result < ( u32 , HostInternal ) , ( ) > {
29692959 path_to_file_url_segments_windows ( path, serialization)
@@ -2972,8 +2962,9 @@ fn path_to_file_url_segments(
29722962#[ cfg( feature = "std" ) ]
29732963// Build this unconditionally to alleviate https://github.com/servo/rust-url/issues/102
29742964#[ cfg_attr( not( windows) , allow( dead_code) ) ]
2965+ #[ cfg( feature = "std" ) ]
29752966fn path_to_file_url_segments_windows (
2976- path : & Path ,
2967+ path : & std :: path :: Path ,
29772968 serialization : & mut String ,
29782969) -> Result < ( u32 , HostInternal ) , ( ) > {
29792970 use crate :: parser:: PATH_SEGMENT ;
@@ -3048,6 +3039,7 @@ fn file_url_segments_to_pathbuf(
30483039 use std:: os:: unix:: prelude:: OsStrExt ;
30493040 #[ cfg( target_os = "wasi" ) ]
30503041 use std:: os:: wasi:: prelude:: OsStrExt ;
3042+ use std:: path:: PathBuf ;
30513043
30523044 if host. is_some ( ) {
30533045 return Err ( ( ) ) ;
@@ -3087,13 +3079,14 @@ fn file_url_segments_to_pathbuf(
30873079fn file_url_segments_to_pathbuf (
30883080 host : Option < & str > ,
30893081 segments : str:: Split < char > ,
3090- ) -> Result < PathBuf , ( ) > {
3082+ ) -> Result < std :: path :: PathBuf , ( ) > {
30913083 file_url_segments_to_pathbuf_windows ( host, segments)
30923084}
30933085
30943086#[ cfg( feature = "std" ) ]
30953087// Build this unconditionally to alleviate https://github.com/servo/rust-url/issues/102
30963088#[ cfg_attr( not( windows) , allow( dead_code) ) ]
3089+ #[ cfg( feature = "std" ) ]
30973090fn file_url_segments_to_pathbuf_windows (
30983091 host : Option < & str > ,
30993092 mut segments : str:: Split < ' _ , char > ,
@@ -3138,7 +3131,7 @@ fn file_url_segments_to_pathbuf_windows(
31383131 Err ( ..) => return Err ( ( ) ) ,
31393132 }
31403133 }
3141- let path = PathBuf :: from ( string) ;
3134+ let path = std :: path :: PathBuf :: from ( string) ;
31423135 debug_assert ! (
31433136 path. is_absolute( ) ,
31443137 "to_file_path() failed to produce an absolute Path"
0 commit comments