|
|
@@ -118,6 +118,9 @@ assert!(css_url.serialize() == "http://servo.github.io/rust-url/main.css".to_str
|
|
|
|
|
|
*/
|
|
|
|
|
|
+#![cfg_attr(feature="heap_size", feature(plugin, custom_derive))]
|
|
|
+#![cfg_attr(feature="heap_size", plugin(heapsize_plugin))]
|
|
|
+
|
|
|
extern crate rustc_serialize;
|
|
|
|
|
|
#[macro_use]
|
|
|
@@ -127,7 +130,7 @@ extern crate matches;
|
|
|
extern crate serde;
|
|
|
|
|
|
#[cfg(feature="heap_size")]
|
|
|
-extern crate heapsize;
|
|
|
+#[macro_use] extern crate heapsize;
|
|
|
|
|
|
use std::fmt::{self, Formatter};
|
|
|
use std::str;
|
|
|
@@ -136,9 +139,6 @@ use std::path::{Path, PathBuf};
|
|
|
#[cfg(feature="serde_serialization")]
|
|
|
use std::str::FromStr;
|
|
|
|
|
|
-#[cfg(feature="heap_size")]
|
|
|
-use heapsize::HeapSizeOf;
|
|
|
-
|
|
|
pub use host::{Host, Ipv6Address};
|
|
|
pub use parser::{ErrorHandler, ParseResult, ParseError};
|
|
|
|
|
|
@@ -162,6 +162,7 @@ mod tests;
|
|
|
|
|
|
/// The parsed representation of an absolute URL.
|
|
|
#[derive(PartialEq, Eq, Clone, Debug, Hash, PartialOrd, Ord)]
|
|
|
+#[cfg_attr(feature="heap_size", derive(HeapSizeOf))]
|
|
|
pub struct Url {
|
|
|
/// The scheme (a.k.a. protocol) of the URL, in ASCII lower case.
|
|
|
pub scheme: String,
|
|
|
@@ -193,6 +194,7 @@ pub struct Url {
|
|
|
|
|
|
/// The components of the URL whose representation depends on where the scheme is *relative*.
|
|
|
#[derive(PartialEq, Eq, Clone, Debug, Hash, PartialOrd, Ord)]
|
|
|
+#[cfg_attr(feature="heap_size", derive(HeapSizeOf))]
|
|
|
pub enum SchemeData {
|
|
|
/// Components for URLs in a *relative* scheme such as HTTP.
|
|
|
Relative(RelativeSchemeData),
|
|
|
@@ -207,6 +209,7 @@ pub enum SchemeData {
|
|
|
|
|
|
/// Components for URLs in a *relative* scheme such as HTTP.
|
|
|
#[derive(PartialEq, Eq, Clone, Debug, Hash, PartialOrd, Ord)]
|
|
|
+#[cfg_attr(feature="heap_size", derive(HeapSizeOf))]
|
|
|
pub struct RelativeSchemeData {
|
|
|
/// The username of the URL, as a possibly empty, percent-encoded string.
|
|
|
///
|
|
|
@@ -1055,52 +1058,3 @@ fn file_url_path_to_pathbuf_windows(path: &[String]) -> Result<PathBuf, ()> {
|
|
|
Ok(path)
|
|
|
}
|
|
|
|
|
|
-#[cfg(feature="heap_size")]
|
|
|
-impl HeapSizeOf for Url {
|
|
|
- fn heap_size_of_children(&self) -> usize {
|
|
|
- // Using a struct pattern without `..` rather than `foo.bar` field access
|
|
|
- // makes sure this will be updated if a field is added.
|
|
|
- let &url::Url { ref scheme, ref scheme_data, ref query, ref fragment } = self;
|
|
|
- scheme.heap_size_of_children() +
|
|
|
- scheme_data.heap_size_of_children() +
|
|
|
- query.heap_size_of_children() +
|
|
|
- fragment.heap_size_of_children()
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#[cfg(feature="heap_size")]
|
|
|
-impl HeapSizeOf for SchemeData {
|
|
|
- fn heap_size_of_children(&self) -> usize {
|
|
|
- match self {
|
|
|
- &url::SchemeData::Relative(ref data) => data.heap_size_of_children(),
|
|
|
- &url::SchemeData::NonRelative(ref str) => str.heap_size_of_children()
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#[cfg(feature="heap_size")]
|
|
|
-impl HeapSizeOf for RelativeSchemeData {
|
|
|
- fn heap_size_of_children(&self) -> usize {
|
|
|
- // Using a struct pattern without `..` rather than `foo.bar` field access
|
|
|
- // makes sure this will be updated if a field is added.
|
|
|
- let &url::RelativeSchemeData { ref username, ref password, ref host,
|
|
|
- ref port, ref default_port, ref path } = self;
|
|
|
- username.heap_size_of_children() +
|
|
|
- password.heap_size_of_children() +
|
|
|
- host.heap_size_of_children() +
|
|
|
- port.heap_size_of_children() +
|
|
|
- default_port.heap_size_of_children() +
|
|
|
- path.heap_size_of_children()
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#[cfg(feature="heap_size")]
|
|
|
-impl HeapSizeOf for Host {
|
|
|
- fn heap_size_of_children(&self) -> usize {
|
|
|
- match self {
|
|
|
- &url::Host::Domain(ref str) => str.heap_size_of_children(),
|
|
|
- &url::Host::Ipv6(_) => 0
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|