diff --git a/benches/client.rs b/benches/client.rs index 266cf043..c75cc030 100644 --- a/benches/client.rs +++ b/benches/client.rs @@ -47,6 +47,7 @@ fn bench_curl(b: &mut test::Bencher) { listening.close().unwrap() } +#[deriving(Clone)] struct Foo; impl hyper::header::Header for Foo { diff --git a/benches/client_mock_tcp.rs b/benches/client_mock_tcp.rs index 0f84cf0c..710b2b1b 100644 --- a/benches/client_mock_tcp.rs +++ b/benches/client_mock_tcp.rs @@ -68,6 +68,7 @@ fn bench_mock_curl(b: &mut test::Bencher) { }); } +#[deriving(Clone)] struct Foo; impl hyper::header::Header for Foo { diff --git a/src/header/common/authorization.rs b/src/header/common/authorization.rs index 2e74ad9f..99225f92 100644 --- a/src/header/common/authorization.rs +++ b/src/header/common/authorization.rs @@ -39,7 +39,7 @@ impl HeaderFormat for Authorization { } /// An Authorization scheme to be used in the header. -pub trait Scheme: FromStr + Send + Sync { +pub trait Scheme: FromStr + Clone + Send + Sync { /// An optional Scheme name. /// /// For example, `Basic asdf` has the name `Basic`. The Option is diff --git a/src/header/mod.rs b/src/header/mod.rs index adbd2dfa..be598074 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -41,17 +41,22 @@ pub trait Header: Typeable + Send + Sync { /// than one field value. If that's the case, you **should** return `None` /// if `raw.len() > 1`. fn parse_header(raw: &[Vec]) -> Option; + } /// A trait for any object that will represent a header field and value. /// /// This trait represents the formatting of a Header for output to a TcpStream. -pub trait HeaderFormat: Typeable + Send + Sync { +pub trait HeaderFormat: Clone + Typeable + Send + Sync { /// Format a header to be output into a TcpStream. /// /// This method is not allowed to introduce an Err not produced /// by the passed-in Formatter. fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result; + + #[doc(hidden)] + #[inline] + fn clone_box(&self) -> Box { box self.clone() } } #[doc(hidden)] @@ -81,12 +86,19 @@ impl<'a> UncheckedAnyMutDowncast<'a> for &'a mut HeaderFormat { } } +impl Clone for Box { + fn clone(&self) -> Box { + self.clone_box() + } +} + fn header_name() -> &'static str { let name = Header::header_name(None::); name } /// A map of header fields on requests and responses. +#[deriving(Clone)] pub struct Headers { data: HashMap, RWLock> } @@ -315,6 +327,7 @@ impl<'a> fmt::Show for HeaderView<'a> { } } +#[deriving(Clone)] struct Item { raw: Option>>, typed: Option> @@ -353,12 +366,19 @@ impl fmt::Show for Item { } } +impl Clone for RWLock { + fn clone(&self) -> RWLock { + RWLock::new(self.read().clone()) + } +} + impl fmt::Show for Box { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { (**self).fmt_header(fmt) } } +#[deriving(Clone)] struct CaseInsensitive(S); impl Str for CaseInsensitive {