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

Auto merge of #216 - nox:serde, r=SimonSapin

Allow serde 0.8 and remove use of compiler plugins

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-url/216)
<!-- Reviewable:end -->
bors-servo 10 лет назад
Родитель
Сommit
51d17bd18c
5 измененных файлов с 47 добавлено и 17 удалено
  1. 6 7
      Cargo.toml
  2. 1 1
      Makefile
  3. 14 2
      src/host.rs
  4. 9 5
      src/lib.rs
  5. 17 2
      src/origin.rs

+ 6 - 7
Cargo.toml

@@ -1,7 +1,7 @@
 [package]
 
 name = "url"
-version = "1.1.1"
+version = "1.2.0"
 authors = ["The rust-url developers"]
 
 description = "URL library for Rust, based on the WHATWG URL Standard"
@@ -27,13 +27,12 @@ rustc-serialize = "0.3"
 
 [features]
 query_encoding = ["encoding"]
-heap_size = ["heapsize", "heapsize_plugin"]
+heap_size = ["heapsize"]
 
 [dependencies]
-idna = { version = "0.1.0", path = "./idna" }
-heapsize = {version = ">=0.1.1, <0.4", optional = true}
-heapsize_plugin = {version = "0.1.0", optional = true}
 encoding = {version = "0.2", optional = true}
-serde = {version = ">=0.6.1, <0.8", optional = true}
-rustc-serialize = {version = "0.3", optional = true}
+heapsize = {version = ">=0.1.1, <0.4", optional = true}
+idna = { version = "0.1.0", path = "./idna" }
 matches = "0.1"
+rustc-serialize = {version = "0.3", optional = true}
+serde = {version = ">=0.6.1, <0.9", optional = true}

+ 1 - 1
Makefile

@@ -1,6 +1,6 @@
 test:
 	cargo test --features "query_encoding serde rustc-serialize"
-	[ x$$TRAVIS_RUST_VERSION != xnightly ] || cargo test --features heap_size
+	[ x$$TRAVIS_RUST_VERSION != xnightly ] || cargo test --features heapsize
 
 doc:
 	cargo doc --features "query_encoding serde rustc-serialize"

+ 14 - 2
src/host.rs

@@ -6,6 +6,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#[cfg(feature = "heapsize")] use heapsize::HeapSizeOf;
 use std::cmp;
 use std::fmt::{self, Formatter};
 use std::io;
@@ -16,7 +17,6 @@ use percent_encoding::percent_decode;
 use idna;
 
 #[derive(Copy, Clone, Debug, Eq, PartialEq)]
-#[cfg_attr(feature="heap_size", derive(HeapSizeOf))]
 pub enum HostInternal {
     None,
     Domain,
@@ -24,6 +24,9 @@ pub enum HostInternal {
     Ipv6(Ipv6Addr),
 }
 
+#[cfg(feature = "heapsize")]
+known_heap_size!(0, HostInternal);
+
 impl<S> From<Host<S>> for HostInternal {
     fn from(host: Host<S>) -> HostInternal {
         match host {
@@ -36,7 +39,6 @@ impl<S> From<Host<S>> for HostInternal {
 
 /// The host name of an URL.
 #[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
-#[cfg_attr(feature="heap_size", derive(HeapSizeOf))]
 pub enum Host<S=String> {
     /// A DNS domain name, as '.' dot-separated labels.
     /// Non-ASCII labels are encoded in punycode per IDNA.
@@ -55,6 +57,16 @@ pub enum Host<S=String> {
     Ipv6(Ipv6Addr),
 }
 
+#[cfg(feature = "heapsize")]
+impl<S: HeapSizeOf> HeapSizeOf for Host<S> {
+    fn heap_size_of_children(&self) -> usize {
+        match *self {
+            Host::Domain(ref s) => s.heap_size_of_children(),
+            _ => 0,
+        }
+    }
+}
+
 impl<'a> Host<&'a str> {
     /// Return a copy of `self` that owns an allocated `String` but does not borrow an `&Url`.
     pub fn to_owned(&self) -> Host<String> {

+ 9 - 5
src/lib.rs

@@ -112,17 +112,15 @@ let css_url = this_document.join("../main.css").unwrap();
 assert_eq!(css_url.as_str(), "http://servo.github.io/rust-url/main.css")
 */
 
-#![cfg_attr(feature="heap_size", feature(plugin, custom_derive))]
-#![cfg_attr(feature="heap_size", plugin(heapsize_plugin))]
-
 #[cfg(feature="rustc-serialize")] extern crate rustc_serialize;
 #[macro_use] extern crate matches;
 #[cfg(feature="serde")] extern crate serde;
-#[cfg(feature="heap_size")] #[macro_use] extern crate heapsize;
+#[cfg(feature="heapsize")] #[macro_use] extern crate heapsize;
 
 pub extern crate idna;
 
 use encoding::EncodingOverride;
+#[cfg(feature = "heapsize")] use heapsize::HeapSizeOf;
 use host::HostInternal;
 use parser::{Parser, Context, SchemeType, to_u32};
 use percent_encoding::{PATH_SEGMENT_ENCODE_SET, USERINFO_ENCODE_SET,
@@ -156,7 +154,6 @@ pub mod quirks;
 
 /// A parsed URL record.
 #[derive(Clone)]
-#[cfg_attr(feature="heap_size", derive(HeapSizeOf))]
 pub struct Url {
     /// Syntax in pseudo-BNF:
     ///
@@ -181,6 +178,13 @@ pub struct Url {
     fragment_start: Option<u32>,  // Before '#', unlike Position::FragmentStart
 }
 
+#[cfg(feature = "heapsize")]
+impl HeapSizeOf for Url {
+    fn heap_size_of_children(&self) -> usize {
+        self.serialization.heap_size_of_children()
+    }
+}
+
 /// Full configuration for the URL parser.
 #[derive(Copy, Clone)]
 pub struct ParseOptions<'a> {

+ 17 - 2
src/origin.rs

@@ -6,6 +6,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#[cfg(feature = "heapsize")] use heapsize::HeapSizeOf;
 use host::Host;
 use idna::domain_to_unicode;
 use parser::default_port;
@@ -34,7 +35,6 @@ pub fn url_origin(url: &Url) -> Origin {
 
 /// The origin of an URL
 #[derive(PartialEq, Eq, Clone, Debug)]
-#[cfg_attr(feature="heap_size", derive(HeapSizeOf))]
 pub enum Origin {
     /// A globally unique identifier
     Opaque(OpaqueOrigin),
@@ -43,6 +43,19 @@ pub enum Origin {
     Tuple(String, Host<String>, u16)
 }
 
+#[cfg(feature = "heapsize")]
+impl HeapSizeOf for Origin {
+    fn heap_size_of_children(&self) -> usize {
+        match *self {
+            Origin::Tuple(ref scheme, ref host, _) => {
+                scheme.heap_size_of_children() +
+                host.heap_size_of_children()
+            },
+            _ => 0,
+        }
+    }
+}
+
 
 impl Origin {
     /// Creates a new opaque origin that is only equal to itself.
@@ -95,5 +108,7 @@ impl Origin {
 
 /// Opaque identifier for URLs that have file or other schemes
 #[derive(Eq, PartialEq, Clone, Debug)]
-#[cfg_attr(feature="heap_size", derive(HeapSizeOf))]
 pub struct OpaqueOrigin(usize);
+
+#[cfg(feature = "heapsize")]
+known_heap_size!(0, OpaqueOrigin);