Explorar el Código

Backport to Rust 1.7

Simon Sapin hace 10 años
padre
commit
2375850090
Se han modificado 3 ficheros con 8 adiciones y 8 borrados
  1. 3 3
      src/encoding.rs
  2. 3 3
      src/form_urlencoded.rs
  3. 2 2
      src/percent_encoding.rs

+ 3 - 3
src/encoding.rs

@@ -81,7 +81,7 @@ impl EncodingOverride {
 
     pub fn encode<'a>(&self, input: Cow<'a, str>) -> Cow<'a, [u8]> {
         match self.encoding {
-            Some(encoding) => encoding.encode(&input, EncoderTrap::NcrEscape).unwrap().into(),
+            Some(encoding) => Cow::Owned(encoding.encode(&input, EncoderTrap::NcrEscape).unwrap()),
             None => encode_utf8(input)
         }
     }
@@ -122,7 +122,7 @@ pub fn decode_utf8_lossy(input: Cow<[u8]>) -> Cow<str> {
 
 pub fn encode_utf8(input: Cow<str>) -> Cow<[u8]> {
     match input {
-        Cow::Borrowed(s) => s.as_bytes().into(),
-        Cow::Owned(s) => s.into_bytes().into()
+        Cow::Borrowed(s) => Cow::Borrowed(s.as_bytes()),
+        Cow::Owned(s) => Cow::Owned(s.into_bytes())
     }
 }

+ 3 - 3
src/form_urlencoded.rs

@@ -112,7 +112,7 @@ impl<'a> Iterator for Parse<'a> {
 fn decode(input: &[u8], encoding: EncodingOverride) -> Cow<str> {
     let replaced = replace_plus(input);
     encoding.decode(match percent_decode(&replaced).if_any() {
-        Some(vec) => vec.into(),
+        Some(vec) => Cow::Owned(vec),
         None => replaced,
     })
 }
@@ -120,7 +120,7 @@ fn decode(input: &[u8], encoding: EncodingOverride) -> Cow<str> {
 /// Replace b'+' with b' '
 fn replace_plus<'a>(input: &'a [u8]) -> Cow<'a, [u8]> {
     match input.iter().position(|&b| b == b'+') {
-        None => input.into(),
+        None => Cow::Borrowed(input),
         Some(first_position) => {
             let mut replaced = input.to_owned();
             replaced[first_position] = b' ';
@@ -129,7 +129,7 @@ fn replace_plus<'a>(input: &'a [u8]) -> Cow<'a, [u8]> {
                     *byte = b' ';
                 }
             }
-            replaced.into()
+            Cow::Owned(replaced)
         }
     }
 }

+ 2 - 2
src/percent_encoding.rs

@@ -288,8 +288,8 @@ impl<'a> Iterator for PercentDecode<'a> {
 impl<'a> From<PercentDecode<'a>> for Cow<'a, [u8]> {
     fn from(iter: PercentDecode<'a>) -> Self {
         match iter.if_any() {
-            Some(vec) => vec.into(),
-            None => iter.bytes.as_slice().into(),
+            Some(vec) => Cow::Owned(vec),
+            None => Cow::Borrowed(iter.bytes.as_slice()),
         }
     }
 }