/rust/registry/src/index.crates.io-1949cf8c6b5b557f/headers-0.4.1/src/util/mod.rs
Line | Count | Source |
1 | | use http::HeaderValue; |
2 | | |
3 | | use crate::Error; |
4 | | |
5 | | //pub use self::charset::Charset; |
6 | | //pub use self::encoding::Encoding; |
7 | | pub(crate) use self::entity::{EntityTag, EntityTagRange}; |
8 | | pub(crate) use self::flat_csv::{FlatCsv, SemiColon}; |
9 | | pub(crate) use self::fmt::fmt; |
10 | | pub(crate) use self::http_date::HttpDate; |
11 | | pub(crate) use self::iter::IterExt; |
12 | | //pub use language_tags::LanguageTag; |
13 | | //pub use self::quality_value::{Quality, QualityValue}; |
14 | | pub(crate) use self::seconds::Seconds; |
15 | | pub(crate) use self::value_string::HeaderValueString; |
16 | | |
17 | | //mod charset; |
18 | | pub(crate) mod csv; |
19 | | //mod encoding; |
20 | | mod entity; |
21 | | mod flat_csv; |
22 | | mod fmt; |
23 | | mod http_date; |
24 | | mod iter; |
25 | | //mod quality_value; |
26 | | mod seconds; |
27 | | mod value_string; |
28 | | |
29 | | macro_rules! error_type { |
30 | | ($name:ident) => { |
31 | | #[doc(hidden)] |
32 | | pub struct $name { |
33 | | _inner: (), |
34 | | } |
35 | | |
36 | | impl ::std::fmt::Debug for $name { |
37 | 0 | fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { |
38 | 0 | f.debug_struct(stringify!($name)).finish() |
39 | 0 | } Unexecuted instantiation: <headers::common::content_range::InvalidContentRange as core::fmt::Debug>::fmt Unexecuted instantiation: <headers::common::etag::InvalidETag as core::fmt::Debug>::fmt Unexecuted instantiation: <headers::common::server::InvalidServer as core::fmt::Debug>::fmt Unexecuted instantiation: <headers::common::range::InvalidRange as core::fmt::Debug>::fmt Unexecuted instantiation: <headers::common::origin::InvalidOrigin as core::fmt::Debug>::fmt Unexecuted instantiation: <headers::common::authorization::InvalidBearerToken as core::fmt::Debug>::fmt Unexecuted instantiation: <headers::common::referer::InvalidReferer as core::fmt::Debug>::fmt Unexecuted instantiation: <headers::common::user_agent::InvalidUserAgent as core::fmt::Debug>::fmt |
40 | | } |
41 | | |
42 | | impl ::std::fmt::Display for $name { |
43 | 0 | fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { |
44 | 0 | f.write_str(stringify!($name)) |
45 | 0 | } Unexecuted instantiation: <headers::common::content_range::InvalidContentRange as core::fmt::Display>::fmt Unexecuted instantiation: <headers::common::etag::InvalidETag as core::fmt::Display>::fmt Unexecuted instantiation: <headers::common::server::InvalidServer as core::fmt::Display>::fmt Unexecuted instantiation: <headers::common::range::InvalidRange as core::fmt::Display>::fmt Unexecuted instantiation: <headers::common::origin::InvalidOrigin as core::fmt::Display>::fmt Unexecuted instantiation: <headers::common::authorization::InvalidBearerToken as core::fmt::Display>::fmt Unexecuted instantiation: <headers::common::referer::InvalidReferer as core::fmt::Display>::fmt Unexecuted instantiation: <headers::common::user_agent::InvalidUserAgent as core::fmt::Display>::fmt |
46 | | } |
47 | | |
48 | | impl ::std::error::Error for $name {} |
49 | | }; |
50 | | } |
51 | | |
52 | | macro_rules! derive_header { |
53 | | ($type:ident(_), name: $name:ident) => { |
54 | | impl crate::Header for $type { |
55 | 0 | fn name() -> &'static ::http::header::HeaderName { |
56 | 0 | &::http::header::$name |
57 | 0 | } Unexecuted instantiation: <headers::common::transfer_encoding::TransferEncoding as headers_core::Header>::name Unexecuted instantiation: <headers::common::cookie::Cookie as headers_core::Header>::name Unexecuted instantiation: <headers::common::connection::Connection as headers_core::Header>::name Unexecuted instantiation: <headers::common::access_control_expose_headers::AccessControlExposeHeaders as headers_core::Header>::name Unexecuted instantiation: <headers::common::access_control_request_headers::AccessControlRequestHeaders as headers_core::Header>::name Unexecuted instantiation: <headers::common::location::Location as headers_core::Header>::name Unexecuted instantiation: <headers::common::upgrade::Upgrade as headers_core::Header>::name Unexecuted instantiation: <headers::common::if_none_match::IfNoneMatch as headers_core::Header>::name Unexecuted instantiation: <headers::common::access_control_allow_headers::AccessControlAllowHeaders as headers_core::Header>::name Unexecuted instantiation: <headers::common::sec_websocket_accept::SecWebsocketAccept as headers_core::Header>::name Unexecuted instantiation: <headers::common::etag::ETag as headers_core::Header>::name Unexecuted instantiation: <headers::common::server::Server as headers_core::Header>::name Unexecuted instantiation: <headers::common::expires::Expires as headers_core::Header>::name Unexecuted instantiation: <headers::common::content_encoding::ContentEncoding as headers_core::Header>::name Unexecuted instantiation: <headers::common::vary::Vary as headers_core::Header>::name Unexecuted instantiation: <headers::common::if_match::IfMatch as headers_core::Header>::name Unexecuted instantiation: <headers::common::sec_websocket_key::SecWebsocketKey as headers_core::Header>::name Unexecuted instantiation: <headers::common::if_range::IfRange as headers_core::Header>::name Unexecuted instantiation: <headers::common::retry_after::RetryAfter as headers_core::Header>::name Unexecuted instantiation: <headers::common::referrer_policy::ReferrerPolicy as headers_core::Header>::name Unexecuted instantiation: <headers::common::access_control_max_age::AccessControlMaxAge as headers_core::Header>::name Unexecuted instantiation: <headers::common::origin::Origin as headers_core::Header>::name Unexecuted instantiation: <headers::common::last_modified::LastModified as headers_core::Header>::name Unexecuted instantiation: <headers::common::if_modified_since::IfModifiedSince as headers_core::Header>::name Unexecuted instantiation: <headers::common::if_unmodified_since::IfUnmodifiedSince as headers_core::Header>::name Unexecuted instantiation: <headers::common::age::Age as headers_core::Header>::name Unexecuted instantiation: <headers::common::content_location::ContentLocation as headers_core::Header>::name Unexecuted instantiation: <headers::common::accept_ranges::AcceptRanges as headers_core::Header>::name Unexecuted instantiation: <headers::common::te::Te as headers_core::Header>::name Unexecuted instantiation: <headers::common::pragma::Pragma as headers_core::Header>::name Unexecuted instantiation: <headers::common::access_control_allow_methods::AccessControlAllowMethods as headers_core::Header>::name Unexecuted instantiation: <headers::common::allow::Allow as headers_core::Header>::name Unexecuted instantiation: <headers::common::referer::Referer as headers_core::Header>::name Unexecuted instantiation: <headers::common::user_agent::UserAgent as headers_core::Header>::name Unexecuted instantiation: <headers::common::access_control_allow_origin::AccessControlAllowOrigin as headers_core::Header>::name Unexecuted instantiation: <headers::common::date::Date as headers_core::Header>::name |
58 | | |
59 | 0 | fn decode<'i, I>(values: &mut I) -> Result<Self, crate::Error> |
60 | 0 | where |
61 | 0 | I: Iterator<Item = &'i ::http::header::HeaderValue>, |
62 | | { |
63 | 0 | crate::util::TryFromValues::try_from_values(values).map($type) |
64 | 0 | } Unexecuted instantiation: <headers::common::content_encoding::ContentEncoding as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::transfer_encoding::TransferEncoding as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::cookie::Cookie as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::connection::Connection as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::content_location::ContentLocation as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::access_control_expose_headers::AccessControlExposeHeaders as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::access_control_request_headers::AccessControlRequestHeaders as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::location::Location as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::accept_ranges::AcceptRanges as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::te::Te as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::pragma::Pragma as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::upgrade::Upgrade as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::if_none_match::IfNoneMatch as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::access_control_allow_headers::AccessControlAllowHeaders as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::access_control_allow_methods::AccessControlAllowMethods as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::vary::Vary as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::allow::Allow as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::if_match::IfMatch as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::sec_websocket_key::SecWebsocketKey as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::sec_websocket_accept::SecWebsocketAccept as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::etag::ETag as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::referer::Referer as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::if_range::IfRange as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::retry_after::RetryAfter as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::referrer_policy::ReferrerPolicy as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::access_control_max_age::AccessControlMaxAge as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::user_agent::UserAgent as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::access_control_allow_origin::AccessControlAllowOrigin as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::origin::Origin as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::server::Server as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::last_modified::LastModified as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::date::Date as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::expires::Expires as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::if_modified_since::IfModifiedSince as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::if_unmodified_since::IfUnmodifiedSince as headers_core::Header>::decode::<_> Unexecuted instantiation: <headers::common::age::Age as headers_core::Header>::decode::<_> |
65 | | |
66 | 0 | fn encode<E: Extend<crate::HeaderValue>>(&self, values: &mut E) { |
67 | 0 | values.extend(::std::iter::once((&self.0).into())); |
68 | 0 | } Unexecuted instantiation: <headers::common::content_encoding::ContentEncoding as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::transfer_encoding::TransferEncoding as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::cookie::Cookie as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::connection::Connection as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::content_location::ContentLocation as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::access_control_expose_headers::AccessControlExposeHeaders as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::access_control_request_headers::AccessControlRequestHeaders as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::location::Location as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::accept_ranges::AcceptRanges as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::te::Te as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::pragma::Pragma as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::upgrade::Upgrade as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::if_none_match::IfNoneMatch as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::access_control_allow_headers::AccessControlAllowHeaders as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::access_control_allow_methods::AccessControlAllowMethods as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::vary::Vary as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::allow::Allow as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::if_match::IfMatch as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::sec_websocket_key::SecWebsocketKey as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::sec_websocket_accept::SecWebsocketAccept as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::etag::ETag as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::referer::Referer as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::if_range::IfRange as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::retry_after::RetryAfter as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::referrer_policy::ReferrerPolicy as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::access_control_max_age::AccessControlMaxAge as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::user_agent::UserAgent as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::access_control_allow_origin::AccessControlAllowOrigin as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::origin::Origin as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::server::Server as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::last_modified::LastModified as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::date::Date as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::expires::Expires as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::if_modified_since::IfModifiedSince as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::if_unmodified_since::IfUnmodifiedSince as headers_core::Header>::encode::<_> Unexecuted instantiation: <headers::common::age::Age as headers_core::Header>::encode::<_> |
69 | | } |
70 | | }; |
71 | | } |
72 | | |
73 | | /// A helper trait for use when deriving `Header`. |
74 | | pub(crate) trait TryFromValues: Sized { |
75 | | /// Try to convert from the values into an instance of `Self`. |
76 | | fn try_from_values<'i, I>(values: &mut I) -> Result<Self, Error> |
77 | | where |
78 | | Self: Sized, |
79 | | I: Iterator<Item = &'i HeaderValue>; |
80 | | } |
81 | | |
82 | | impl TryFromValues for HeaderValue { |
83 | 0 | fn try_from_values<'i, I>(values: &mut I) -> Result<Self, Error> |
84 | 0 | where |
85 | 0 | I: Iterator<Item = &'i HeaderValue>, |
86 | | { |
87 | 0 | values.next().cloned().ok_or_else(Error::invalid) |
88 | 0 | } |
89 | | } |