@@ -130,6 +130,15 @@ url = { version = "2", features = ["serde"] }
130130
131131pub use form_urlencoded;
132132
133+ // For forwards compatibility
134+ #[ cfg( feature = "std" ) ]
135+ extern crate std;
136+
137+ extern crate alloc;
138+
139+ #[ cfg( not( feature = "alloc" ) ) ]
140+ compile_error ! ( "the `alloc` feature must be enabled" ) ;
141+
133142#[ cfg( feature = "serde" ) ]
134143extern crate serde;
135144
@@ -1317,9 +1326,23 @@ impl Url {
13171326 ///
13181327 /// ```
13191328 /// use url::Url;
1320- /// # use std::error::Error;
13211329 ///
1322- /// # fn run() -> Result<(), Box<dyn Error>> {
1330+ /// # use url::ParseError;
1331+ /// # #[derive(Debug)]
1332+ /// # /// A simple wrapper error struct for `no_std` support
1333+ /// # struct TestError;
1334+ /// # impl From<ParseError> for TestError {
1335+ /// # fn from(value: ParseError) -> Self {
1336+ /// # TestError {}
1337+ /// # }
1338+ /// # }
1339+ /// # impl From<&str> for TestError {
1340+ /// # fn from(value: &str) -> Self {
1341+ /// # TestError {}
1342+ /// # }
1343+ /// # }
1344+ ///
1345+ /// # fn run() -> Result<(), TestError> {
13231346 /// let url = Url::parse("https://example.com/foo/bar")?;
13241347 /// let mut path_segments = url.path_segments().ok_or_else(|| "cannot be base")?;
13251348 /// assert_eq!(path_segments.next(), Some("foo"));
@@ -1724,9 +1747,22 @@ impl Url {
17241747 ///
17251748 /// ```
17261749 /// use url::Url;
1727- /// # use std::error::Error;
1750+ /// # use url::ParseError;
1751+ /// # #[derive(Debug)]
1752+ /// # /// A simple wrapper error struct for `no_std` support
1753+ /// # struct TestError;
1754+ /// # impl From<ParseError> for TestError {
1755+ /// # fn from(value: ParseError) -> Self {
1756+ /// # TestError {}
1757+ /// # }
1758+ /// # }
1759+ /// # impl From<&str> for TestError {
1760+ /// # fn from(value: &str) -> Self {
1761+ /// # TestError {}
1762+ /// # }
1763+ /// # }
17281764 ///
1729- /// # fn run() -> Result<(), Box<dyn Error> > {
1765+ /// # fn run() -> Result<(), TestError > {
17301766 /// let mut url = Url::parse("ssh://example.net:2048/")?;
17311767 ///
17321768 /// url.set_port(Some(4096)).map_err(|_| "cannot be base")?;
@@ -1743,9 +1779,22 @@ impl Url {
17431779 ///
17441780 /// ```rust
17451781 /// use url::Url;
1746- /// # use std::error::Error;
1782+ /// # use url::ParseError;
1783+ /// # #[derive(Debug)]
1784+ /// # /// A simple wrapper error struct for `no_std` support
1785+ /// # struct TestError;
1786+ /// # impl From<ParseError> for TestError {
1787+ /// # fn from(value: ParseError) -> Self {
1788+ /// # TestError {}
1789+ /// # }
1790+ /// # }
1791+ /// # impl From<&str> for TestError {
1792+ /// # fn from(value: &str) -> Self {
1793+ /// # TestError {}
1794+ /// # }
1795+ /// # }
17471796 ///
1748- /// # fn run() -> Result<(), Box<dyn Error> > {
1797+ /// # fn run() -> Result<(), TestError > {
17491798 /// let mut url = Url::parse("https://example.org/")?;
17501799 ///
17511800 /// url.set_port(Some(443)).map_err(|_| "cannot be base")?;
@@ -2428,7 +2477,10 @@ impl Url {
24282477 /// ```
24292478 ///
24302479 /// This method is only available if the `std` Cargo feature is enabled.
2431- #[ cfg( all( feature = "std" , any( unix, windows, target_os = "redox" , target_os = "wasi" ) ) ) ]
2480+ #[ cfg( all(
2481+ feature = "std" ,
2482+ any( unix, windows, target_os = "redox" , target_os = "wasi" )
2483+ ) ) ]
24322484 #[ allow( clippy:: result_unit_err) ]
24332485 pub fn from_file_path < P : AsRef < Path > > ( path : P ) -> Result < Url , ( ) > {
24342486 let mut serialization = "file://" . to_owned ( ) ;
@@ -2467,7 +2519,10 @@ impl Url {
24672519 /// and usually does not include them (e.g. in `Path::parent()`).
24682520 ///
24692521 /// This method is only available if the `std` Cargo feature is enabled.
2470- #[ cfg( all( feature = "std" , any( unix, windows, target_os = "redox" , target_os = "wasi" ) ) ) ]
2522+ #[ cfg( all(
2523+ feature = "std" ,
2524+ any( unix, windows, target_os = "redox" , target_os = "wasi" )
2525+ ) ) ]
24712526 #[ allow( clippy:: result_unit_err) ]
24722527 pub fn from_directory_path < P : AsRef < Path > > ( path : P ) -> Result < Url , ( ) > {
24732528 let mut url = Url :: from_file_path ( path) ?;
@@ -2586,7 +2641,10 @@ impl Url {
25862641 ///
25872642 /// This method is only available if the `std` Cargo feature is enabled.
25882643 #[ inline]
2589- #[ cfg( all( feature = "std" , any( unix, windows, target_os = "redox" , target_os = "wasi" ) ) ) ]
2644+ #[ cfg( all(
2645+ feature = "std" ,
2646+ any( unix, windows, target_os = "redox" , target_os = "wasi" )
2647+ ) ) ]
25902648 #[ allow( clippy:: result_unit_err) ]
25912649 pub fn to_file_path ( & self ) -> Result < PathBuf , ( ) > {
25922650 if let Some ( segments) = self . path_segments ( ) {
@@ -2902,7 +2960,6 @@ fn file_url_segments_to_pathbuf(
29022960 host : Option < & str > ,
29032961 segments : str:: Split < ' _ , char > ,
29042962) -> Result < PathBuf , ( ) > {
2905- use alloc:: vec:: Vec ;
29062963 use percent_encoding:: percent_decode;
29072964 use std:: ffi:: OsStr ;
29082965 #[ cfg( any( unix, target_os = "redox" ) ) ]
0 commit comments