Explorar el Código

Have a single `impl Url` block with public methods.

Otherwise they show up separately in rustdoc.
Simon Sapin hace 10 años
padre
commit
f6996c8d33
Se han modificado 2 ficheros con 38 adiciones y 38 borrados
  1. 21 15
      src/lib.rs
  2. 17 23
      src/origin.rs

+ 21 - 15
src/lib.rs

@@ -347,6 +347,15 @@ impl Url {
         }
     }
 
+    /// Return the origin of this URL (https://url.spec.whatwg.org/#origin)
+    ///
+    /// Note: this return an opaque origin for `file:` URLs, which causes
+    /// `url.origin() != url.origin()`.
+    #[inline]
+    pub fn origin(&self) -> Origin {
+        origin::url_origin(self)
+    }
+
     /// Return the scheme of this URL, lower-cased, as an ASCII string without the ':' delimiter.
     #[inline]
     pub fn scheme(&self) -> &str {
@@ -668,22 +677,7 @@ impl Url {
         let query = UrlQuery { url: self, fragment: fragment };
         form_urlencoded::Serializer::for_suffix(query, query_start + "?".len())
     }
-}
-
-
-/// Implementation detail of `Url::mutate_query_pairs`. Typically not used directly.
-pub struct UrlQuery<'a> {
-    url: &'a mut Url,
-    fragment: Option<String>,
-}
 
-impl<'a> Drop for UrlQuery<'a> {
-    fn drop(&mut self) {
-        self.url.restore_already_parsed_fragment(self.fragment.take())
-    }
-}
-
-impl Url {
     /// Change this URL’s path.
     pub fn set_path(&mut self, path: &str) {
         let (old_after_path_pos, after_path) = match (self.query_start, self.fragment_start) {
@@ -1365,3 +1359,15 @@ fn file_url_segments_to_pathbuf_windows(mut segments: str::Split<char>) -> Resul
 fn io_error<T>(reason: &str) -> io::Result<T> {
     Err(io::Error::new(io::ErrorKind::InvalidData, reason))
 }
+
+/// Implementation detail of `Url::mutate_query_pairs`. Typically not used directly.
+pub struct UrlQuery<'a> {
+    url: &'a mut Url,
+    fragment: Option<String>,
+}
+
+impl<'a> Drop for UrlQuery<'a> {
+    fn drop(&mut self) {
+        self.url.restore_already_parsed_fragment(self.fragment.take())
+    }
+}

+ 17 - 23
src/origin.rs

@@ -12,29 +12,23 @@ use parser::default_port;
 use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
 use Url;
 
-impl Url {
-    /// Return the origin of this URL (https://url.spec.whatwg.org/#origin)
-    ///
-    /// Note: this return an opaque origin for `file:` URLs, which causes
-    /// `url.origin() != url.origin()`.
-    pub fn origin(&self) -> Origin {
-        let scheme = self.scheme();
-        match scheme {
-            "blob" => {
-                let result = Url::parse(self.path());
-                match result {
-                    Ok(ref url) => url.origin(),
-                    Err(_)  => Origin::new_opaque()
-                }
-            },
-            "ftp" | "gopher" | "http" | "https" | "ws" | "wss" => {
-                Origin::Tuple(scheme.to_owned(), self.host().unwrap().to_owned(),
-                    self.port_or_known_default().unwrap())
-            },
-            // TODO: Figure out what to do if the scheme is a file
-            "file" => Origin::new_opaque(),
-            _ => Origin::new_opaque()
-        }
+pub fn url_origin(url: &Url) -> Origin {
+    let scheme = url.scheme();
+    match scheme {
+        "blob" => {
+            let result = Url::parse(url.path());
+            match result {
+                Ok(ref url) => url_origin(url),
+                Err(_)  => Origin::new_opaque()
+            }
+        },
+        "ftp" | "gopher" | "http" | "https" | "ws" | "wss" => {
+            Origin::Tuple(scheme.to_owned(), url.host().unwrap().to_owned(),
+                url.port_or_known_default().unwrap())
+        },
+        // TODO: Figure out what to do if the scheme is a file
+        "file" => Origin::new_opaque(),
+        _ => Origin::new_opaque()
     }
 }