Просмотр исходного кода

Remove unused ParseError variants

Simon Sapin 10 лет назад
Родитель
Сommit
42b57d398a
2 измененных файлов с 7 добавлено и 25 удалено
  1. 3 3
      src/host.rs
  2. 4 22
      src/parser.rs

+ 3 - 3
src/host.rs

@@ -161,7 +161,7 @@ fn longest_zero_sequence(pieces: &[u16; 8]) -> (isize, isize) {
 }
 
 
-fn parse_ipv4number(mut input: &str) -> ParseResult<u32> {
+fn parse_ipv4number(mut input: &str) -> Result<u32, ()> {
     let mut r = 10;
     if input.starts_with("0x") || input.starts_with("0X") {
         input = &input[2..];
@@ -174,11 +174,11 @@ fn parse_ipv4number(mut input: &str) -> ParseResult<u32> {
         return Ok(0);
     }
     if input.starts_with("+") {
-        return Err(ParseError::InvalidIpv4Address)
+        return Err(())
     }
     match u32::from_str_radix(&input, r) {
         Ok(number) => Ok(number),
-        Err(_) => Err(ParseError::InvalidIpv4Address),
+        Err(_) => Err(()),
     }
 }
 

+ 4 - 22
src/parser.rs

@@ -44,30 +44,12 @@ macro_rules! simple_enum_error {
 simple_enum_error! {
     EmptyHost => "empty host",
     IdnaError => "invalid international domain name",
-    InvalidScheme => "invalid scheme",
     InvalidPort => "invalid port number",
     InvalidIpv4Address => "invalid IPv4 address",
     InvalidIpv6Address => "invalid IPv6 address",
     InvalidDomainCharacter => "invalid domain character",
-    InvalidCharacter => "invalid character",
-    InvalidBackslash => "invalid backslash",
-    InvalidPercentEncoded => "invalid percent-encoded sequence",
-    InvalidAtSymbolInUser => "invalid @-symbol in user",
-    ExpectedTwoSlashes => "expected two slashes (//)",
-    ExpectedInitialSlash => "expected the input to start with a slash",
-    NonUrlCodePoint => "non URL code point",
-    RelativeUrlWithScheme => "relative URL with scheme",
     RelativeUrlWithoutBase => "relative URL without a base",
     RelativeUrlWithNonRelativeBase => "relative URL with a non-relative base",
-    NonAsciiDomainsNotSupportedYet => "non-ASCII domains are not supported yet",
-    CannotSetJavascriptFragment => "cannot set fragment on javascript: URL",
-    CannotSetPortWithFileLikeScheme => "cannot set port with file-like scheme",
-    CannotSetUsernameWithNonRelativeScheme => "cannot set username with non-relative scheme",
-    CannotSetPasswordWithNonRelativeScheme => "cannot set password with non-relative scheme",
-    CannotSetHostPortWithNonRelativeScheme => "cannot set host and port with non-relative scheme",
-    CannotSetHostWithNonRelativeScheme => "cannot set host with non-relative scheme",
-    CannotSetPortWithNonRelativeScheme => "cannot set port with non-relative scheme",
-    CannotSetPathWithNonRelativeScheme => "cannot set path with non-relative scheme",
     Overflow => "URLs more than 4 GB are not supported",
 }
 
@@ -174,9 +156,9 @@ impl<'a> Parser<'a> {
         }
     }
 
-    pub fn parse_scheme<'i>(&mut self, input: &'i str, context: Context) -> ParseResult<&'i str> {
+    pub fn parse_scheme<'i>(&mut self, input: &'i str, context: Context) -> Result<&'i str, ()> {
         if input.is_empty() || !input.starts_with(ascii_alpha) {
-            return Err(ParseError::InvalidScheme)
+            return Err(())
         }
         debug_assert!(self.serialization.is_empty());
         for (i, c) in input.char_indices() {
@@ -187,7 +169,7 @@ impl<'a> Parser<'a> {
                 ':' => return Ok(&input[i + 1..]),
                 _ => {
                     self.serialization.clear();
-                    return Err(ParseError::InvalidScheme)
+                    return Err(())
                 }
             }
         }
@@ -196,7 +178,7 @@ impl<'a> Parser<'a> {
             Context::Setter => Ok(""),
             Context::UrlParser => {
                 self.serialization.clear();
-                Err(ParseError::InvalidScheme)
+                Err(())
             }
         }
     }