@@ -1467,10 +1467,10 @@ impl Url {
1467
1467
/// # }
1468
1468
/// # run().unwrap();
1469
1469
/// ```
1470
- pub fn set_port ( & mut self , mut port : Option < u16 > ) -> Result < ( ) , ( ) > {
1470
+ pub fn set_port ( & mut self , mut port : Option < u16 > ) -> Result < ( ) , ParseError > {
1471
1471
// has_host implies !cannot_be_a_base
1472
1472
if !self . has_host ( ) || self . host ( ) == Some ( Host :: Domain ( "" ) ) || self . scheme ( ) == "file" {
1473
- return Err ( ( ) )
1473
+ return Err ( ParseError :: EmptyHost )
1474
1474
}
1475
1475
if port. is_some ( ) && port == parser:: default_port ( self . scheme ( ) ) {
1476
1476
port = None
@@ -1697,9 +1697,9 @@ impl Url {
1697
1697
/// # run().unwrap();
1698
1698
/// ```
1699
1699
///
1700
- pub fn set_ip_host ( & mut self , address : IpAddr ) -> Result < ( ) , ( ) > {
1700
+ pub fn set_ip_host ( & mut self , address : IpAddr ) -> Result < ( ) , ParseError > {
1701
1701
if self . cannot_be_a_base ( ) {
1702
- return Err ( ( ) )
1702
+ return Err ( ParseError :: SetHostOnCannotBeABaseUrl )
1703
1703
}
1704
1704
1705
1705
let address = match address {
@@ -1736,10 +1736,10 @@ impl Url {
1736
1736
/// # }
1737
1737
/// # run().unwrap();
1738
1738
/// ```
1739
- pub fn set_password ( & mut self , password : Option < & str > ) -> Result < ( ) , ( ) > {
1739
+ pub fn set_password ( & mut self , password : Option < & str > ) -> Result < ( ) , ParseError > {
1740
1740
// has_host implies !cannot_be_a_base
1741
1741
if !self . has_host ( ) || self . host ( ) == Some ( Host :: Domain ( "" ) ) || self . scheme ( ) == "file" {
1742
- return Err ( ( ) )
1742
+ return Err ( ParseError :: EmptyHost )
1743
1743
}
1744
1744
if let Some ( password) = password {
1745
1745
let host_and_after = self . slice ( self . host_start ..) . to_owned ( ) ;
@@ -1818,10 +1818,10 @@ impl Url {
1818
1818
/// # }
1819
1819
/// # run().unwrap();
1820
1820
/// ```
1821
- pub fn set_username ( & mut self , username : & str ) -> Result < ( ) , ( ) > {
1821
+ pub fn set_username ( & mut self , username : & str ) -> Result < ( ) , ParseError > {
1822
1822
// has_host implies !cannot_be_a_base
1823
1823
if !self . has_host ( ) || self . host ( ) == Some ( Host :: Domain ( "" ) ) || self . scheme ( ) == "file" {
1824
- return Err ( ( ) )
1824
+ return Err ( ParseError :: EmptyHost )
1825
1825
}
1826
1826
let username_start = self . scheme_end + 3 ;
1827
1827
debug_assert ! ( self . slice( self . scheme_end..username_start) == "://" ) ;
@@ -1922,12 +1922,12 @@ impl Url {
1922
1922
/// # }
1923
1923
/// # run().unwrap();
1924
1924
/// ```
1925
- pub fn set_scheme ( & mut self , scheme : & str ) -> Result < ( ) , ( ) > {
1925
+ pub fn set_scheme ( & mut self , scheme : & str ) -> Result < ( ) , ParseError > {
1926
1926
let mut parser = Parser :: for_setter ( String :: new ( ) ) ;
1927
1927
let remaining = parser. parse_scheme ( parser:: Input :: new ( scheme) ) ?;
1928
1928
if !remaining. is_empty ( ) ||
1929
1929
( !self . has_host ( ) && SchemeType :: from ( & parser. serialization ) . is_special ( ) ) {
1930
- return Err ( ( ) )
1930
+ return Err ( ParseError :: InvalidScheme )
1931
1931
}
1932
1932
let old_scheme_end = self . scheme_end ;
1933
1933
let new_scheme_end = to_u32 ( parser. serialization . len ( ) ) . unwrap ( ) ;
@@ -1962,7 +1962,7 @@ impl Url {
1962
1962
/// # if cfg!(unix) {
1963
1963
/// use url::Url;
1964
1964
///
1965
- /// # fn run() -> Result<(), () > {
1965
+ /// # fn run() -> Result<(), url::ParseError > {
1966
1966
/// let url = Url::from_file_path("/tmp/foo.txt")?;
1967
1967
/// assert_eq!(url.as_str(), "file:///tmp/foo.txt");
1968
1968
///
@@ -1977,7 +1977,7 @@ impl Url {
1977
1977
/// # }
1978
1978
/// ```
1979
1979
#[ cfg( any( unix, windows, target_os="redox" ) ) ]
1980
- pub fn from_file_path < P : AsRef < Path > > ( path : P ) -> Result < Url , ( ) > {
1980
+ pub fn from_file_path < P : AsRef < Path > > ( path : P ) -> Result < Url , ParseError > {
1981
1981
let mut serialization = "file://" . to_owned ( ) ;
1982
1982
let host_start = serialization. len ( ) as u32 ;
1983
1983
let ( host_end, host) = path_to_file_url_segments ( path. as_ref ( ) , & mut serialization) ?;
@@ -2013,7 +2013,7 @@ impl Url {
2013
2013
/// Note that `std::path` does not consider trailing slashes significant
2014
2014
/// and usually does not include them (e.g. in `Path::parent()`).
2015
2015
#[ cfg( any( unix, windows, target_os="redox" ) ) ]
2016
- pub fn from_directory_path < P : AsRef < Path > > ( path : P ) -> Result < Url , ( ) > {
2016
+ pub fn from_directory_path < P : AsRef < Path > > ( path : P ) -> Result < Url , ParseError > {
2017
2017
let mut url = Url :: from_file_path ( path) ?;
2018
2018
if !url. serialization . ends_with ( '/' ) {
2019
2019
url. serialization . push ( '/' )
@@ -2088,26 +2088,26 @@ impl Url {
2088
2088
/// let path = url.to_file_path();
2089
2089
/// ```
2090
2090
///
2091
- /// Returns `Err` if the host is neither empty nor `"localhost"` (except on Windows, where
2091
+ /// Returns `Err(ParseError::InvalidLocalPath) ` if the host is neither empty nor `"localhost"` (except on Windows, where
2092
2092
/// `file:` URLs may have a non-local host),
2093
2093
/// or if `Path::new_opt()` returns `None`.
2094
2094
/// (That is, if the percent-decoded path contains a NUL byte or,
2095
2095
/// for a Windows path, is not UTF-8.)
2096
2096
#[ inline]
2097
2097
#[ cfg( any( unix, windows, target_os="redox" ) ) ]
2098
- pub fn to_file_path ( & self ) -> Result < PathBuf , ( ) > {
2098
+ pub fn to_file_path ( & self ) -> Result < PathBuf , ParseError > {
2099
2099
if let Some ( segments) = self . path_segments ( ) {
2100
2100
let host = match self . host ( ) {
2101
2101
None | Some ( Host :: Domain ( "localhost" ) ) => None ,
2102
2102
Some ( _) if cfg ! ( windows) && self . scheme ( ) == "file" => {
2103
2103
Some ( & self . serialization [ self . host_start as usize .. self . host_end as usize ] )
2104
2104
} ,
2105
- _ => return Err ( ( ) )
2105
+ _ => return Err ( ParseError :: InvalidLocalPath )
2106
2106
} ;
2107
2107
2108
2108
return file_url_segments_to_pathbuf ( host, segments) ;
2109
2109
}
2110
- Err ( ( ) )
2110
+ Err ( ParseError :: InvalidLocalPath )
2111
2111
}
2112
2112
2113
2113
// Private helper methods:
@@ -2268,10 +2268,10 @@ impl serde::Deserialize for Url {
2268
2268
2269
2269
#[ cfg( any( unix, target_os = "redox" ) ) ]
2270
2270
fn path_to_file_url_segments ( path : & Path , serialization : & mut String )
2271
- -> Result < ( u32 , HostInternal ) , ( ) > {
2271
+ -> Result < ( u32 , HostInternal ) , ParseError > {
2272
2272
use std:: os:: unix:: prelude:: OsStrExt ;
2273
2273
if !path. is_absolute ( ) {
2274
- return Err ( ( ) )
2274
+ return Err ( ParseError :: PathNotAbsolute )
2275
2275
}
2276
2276
let host_end = to_u32 ( serialization. len ( ) ) . unwrap ( ) ;
2277
2277
let mut empty = true ;
@@ -2343,13 +2343,13 @@ fn path_to_file_url_segments_windows(path: &Path, serialization: &mut String)
2343
2343
2344
2344
2345
2345
#[ cfg( any( unix, target_os = "redox" ) ) ]
2346
- fn file_url_segments_to_pathbuf ( host : Option < & str > , segments : str:: Split < char > ) -> Result < PathBuf , ( ) > {
2346
+ fn file_url_segments_to_pathbuf ( host : Option < & str > , segments : str:: Split < char > ) -> Result < PathBuf , ParseError > {
2347
2347
use std:: ffi:: OsStr ;
2348
2348
use std:: os:: unix:: prelude:: OsStrExt ;
2349
2349
use std:: path:: PathBuf ;
2350
2350
2351
2351
if host. is_some ( ) {
2352
- return Err ( ( ) ) ;
2352
+ return Err ( ParseError :: InvalidLocalPath ) ;
2353
2353
}
2354
2354
2355
2355
let mut bytes = if cfg ! ( target_os = "redox" ) {
0 commit comments