Ver Fonte

Add Url::into_string

Simon Sapin há 10 anos atrás
pai
commit
4ee76816b8
1 ficheiros alterados com 11 adições e 0 exclusões
  1. 11 0
      src/lib.rs

+ 11 - 0
src/lib.rs

@@ -218,11 +218,22 @@ impl Url {
         }.parse_url(input)
         }.parse_url(input)
     }
     }
 
 
+    /// Return the serialization of this URL.
+    ///
+    /// This is fast since that serialization is already stored in the `Url` struct.
     #[inline]
     #[inline]
     pub fn as_str(&self) -> &str {
     pub fn as_str(&self) -> &str {
         &self.serialization
         &self.serialization
     }
     }
 
 
+    /// Return the serialization of this URL.
+    ///
+    /// This consumes the `Url` and takes ownership of the `String` stored in it.
+    #[inline]
+    pub fn into_string(self) -> String {
+        self.serialization
+    }
+
     /// Return the scheme of this URL, lower-cased, as an ASCII string without the ':' delimiter.
     /// Return the scheme of this URL, lower-cased, as an ASCII string without the ':' delimiter.
     #[inline]
     #[inline]
     pub fn scheme(&self) -> &str {
     pub fn scheme(&self) -> &str {