mirror of https://github.com/rwf2/Rocket.git
Remove custom 'docify!' macro: use '#[doc]`.
This commit is contained in:
parent
67ad8316dc
commit
3e33cfe37c
|
@ -1,76 +0,0 @@
|
||||||
macro_rules! docify {
|
|
||||||
([$($doc:tt)*]; $($tt:tt)*) => {
|
|
||||||
docify!([$($doc)*] [] $($tt)*);
|
|
||||||
};
|
|
||||||
|
|
||||||
// FIXME: Treat $a just like everywhere else. What if we start with @[]?
|
|
||||||
([$a:tt $($b:tt)*] [] $($tt:tt)*) => {
|
|
||||||
docify!([$($b)*] [stringify!($a), " "] $($tt)*);
|
|
||||||
};
|
|
||||||
|
|
||||||
([@fence @$lang:tt $($b:tt)*] [$($c:tt)+] $($tt:tt)*) => {
|
|
||||||
docify!([$($b)*] [$($c)+, "\n\n```", stringify!($lang), "\n"] $($tt)*);
|
|
||||||
};
|
|
||||||
|
|
||||||
([@fence $($b:tt)*] [$($c:tt)+] $($tt:tt)*) => {
|
|
||||||
docify!([$($b)*] [$($c)+, "\n\n```\n"] $($tt)*);
|
|
||||||
};
|
|
||||||
|
|
||||||
([@{$($a:tt),*}! $($b:tt)*] [$($c:tt)+] $($tt:tt)*) => {
|
|
||||||
docify!([$($b)*] [$($c)+, $($a),*] $($tt)*);
|
|
||||||
};
|
|
||||||
|
|
||||||
([@{$($a:tt),*} $($b:tt)*] [$($c:tt)+] $($tt:tt)*) => {
|
|
||||||
docify!([$($b)*] [$($c)+, $($a),*, " "] $($tt)*);
|
|
||||||
};
|
|
||||||
|
|
||||||
([@code{$($a:tt)+}! $($b:tt)*] [$($c:tt)+] $($tt:tt)*) => {
|
|
||||||
docify!([$($b)*] [$($c)+, "`", $(stringify!($a)),*, "`"] $($tt)*);
|
|
||||||
};
|
|
||||||
|
|
||||||
([@code{$($a:tt)+} $($b:tt)*] [$($c:tt)+] $($tt:tt)*) => {
|
|
||||||
docify!([$($b)*] [$($c)+, "`", $(stringify!($a)),*, "` "] $($tt)*);
|
|
||||||
};
|
|
||||||
|
|
||||||
([@[$($a:tt)*]! $($b:tt)*] [$($c:tt)+] $($tt:tt)*) => {
|
|
||||||
docify!([$($b)*] [$($c)+, $(stringify!($a)),*] $($tt)*);
|
|
||||||
};
|
|
||||||
|
|
||||||
([@[$($a:tt)*] $($b:tt)*] [$($c:tt)+] $($tt:tt)*) => {
|
|
||||||
docify!([$($b)*] [$($c)+, $(stringify!($a)),*, " "] $($tt)*);
|
|
||||||
};
|
|
||||||
|
|
||||||
([@nl $($b:tt)*] [$($c:tt)+] $($tt:tt)*) => {
|
|
||||||
docify!([$($b)*] [$($c)+, "\n"] $($tt)*);
|
|
||||||
};
|
|
||||||
|
|
||||||
(@punct [$a:tt $p:tt $($b:tt)*] [$($c:tt)+] $($tt:tt)*) => {
|
|
||||||
docify!([$($b)*] [$($c)+, stringify!($a), stringify!($p), " "] $($tt)*);
|
|
||||||
};
|
|
||||||
|
|
||||||
(@upunct [$a:tt $p:tt $($b:tt)*] [$($c:tt)+] $($tt:tt)*) => {
|
|
||||||
docify!([$($b)*] [$($c)+, stringify!($a), stringify!($p)] $($tt)*);
|
|
||||||
};
|
|
||||||
|
|
||||||
([$a:tt . $($b:tt)*] $($rest:tt)+) => { docify!(@punct [$a . $($b)*] $($rest)+); };
|
|
||||||
([$a:tt , $($b:tt)*] $($rest:tt)+) => { docify!(@punct [$a , $($b)*] $($rest)+); };
|
|
||||||
([$a:tt ; $($b:tt)*] $($rest:tt)+) => { docify!(@punct [$a ; $($b)*] $($rest)+); };
|
|
||||||
([$a:tt : $($b:tt)*] $($rest:tt)+) => { docify!(@punct [$a : $($b)*] $($rest)+); };
|
|
||||||
([$a:tt ! $($b:tt)*] $($rest:tt)+) => { docify!(@punct [$a ! $($b)*] $($rest)+); };
|
|
||||||
([$a:tt ! $($b:tt)*] $($rest:tt)+) => { docify!(@punct [$a ! $($b)*] $($rest)+); };
|
|
||||||
|
|
||||||
([$a:tt :: $($b:tt)*] $($rest:tt)+) => { docify!(@upunct [$a :: $($b)*] $($rest)+); };
|
|
||||||
|
|
||||||
([$a:tt $($b:tt)*] [$($c:tt)+] $($tt:tt)*) => {
|
|
||||||
docify!([$($b)*] [$($c)+, stringify!($a), " "] $($tt)*);
|
|
||||||
};
|
|
||||||
|
|
||||||
([] [$($doc:expr),*] $($tt:tt)*) => {
|
|
||||||
docify!(concat!($($doc),*), $($tt)*);
|
|
||||||
};
|
|
||||||
|
|
||||||
($x:expr, $($tt:tt)*) => {
|
|
||||||
#[doc = $x]
|
|
||||||
$($tt)*
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -44,33 +44,37 @@ use crate::ext::IntoCollection;
|
||||||
pub struct ContentType(pub MediaType);
|
pub struct ContentType(pub MediaType);
|
||||||
|
|
||||||
macro_rules! content_types {
|
macro_rules! content_types {
|
||||||
($($name:ident ($check:ident): $str:expr, $t:expr,
|
(
|
||||||
$s:expr $(; $k:expr => $v:expr)*,)+) => {
|
$(
|
||||||
|
$name:ident ($check:ident): $str:expr,
|
||||||
|
$t:expr, $s:expr $(; $k:expr => $v:expr)*,
|
||||||
|
)+
|
||||||
|
) => {
|
||||||
$(
|
$(
|
||||||
docify!([
|
|
||||||
Content Type for @{"**"}! @{$str}! @{"**"}!: @{"`"} @{$t}! @[/]! @{$s}!
|
/// Content Type for
|
||||||
$(; @{$k}! @[=]! @{$v}!)* @{"`"}!.
|
#[doc = concat!("**", $str, "**: ")]
|
||||||
];
|
#[doc = concat!("`", $t, "/", $s, $("; ", $k, "=", $v,)* "`")]
|
||||||
#[allow(non_upper_case_globals)]
|
|
||||||
pub const $name: ContentType = ContentType(MediaType::$name);
|
#[allow(non_upper_case_globals)]
|
||||||
);
|
pub const $name: ContentType = ContentType(MediaType::$name);
|
||||||
)+
|
)+
|
||||||
}}
|
}}
|
||||||
|
|
||||||
macro_rules! from_extension {
|
macro_rules! from_extension {
|
||||||
($($ext:expr => $name:ident,)*) => (
|
($($ext:expr => $name:ident,)*) => (
|
||||||
docify!([
|
/// Returns the Content-Type associated with the extension `ext`.
|
||||||
Returns the @[Content-Type] associated with the extension @code{ext}.
|
///
|
||||||
Not all extensions are recognized. If an extensions is not recognized,
|
/// Extensions are matched case-insensitively. Not all extensions are
|
||||||
@code{None} is returned. The currently recognized extensions are:
|
/// recognized. If an extensions is not recognized, `None` is returned.
|
||||||
|
/// The currently recognized extensions are:
|
||||||
@nl
|
///
|
||||||
$(* @{$ext} - @{"`ContentType::"}! @[$name]! @{"`"} @nl)*
|
$(
|
||||||
@nl
|
#[doc = concat!("* ", $ext, " - [`ContentType::", stringify!($name), "`]")]
|
||||||
|
)*
|
||||||
This list is likely to grow. Extensions are matched
|
///
|
||||||
@[case-insensitively.]
|
/// This list is likely to grow.
|
||||||
];
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// Recognized content types:
|
/// Recognized content types:
|
||||||
|
@ -99,19 +103,19 @@ macro_rules! from_extension {
|
||||||
pub fn from_extension(ext: &str) -> Option<ContentType> {
|
pub fn from_extension(ext: &str) -> Option<ContentType> {
|
||||||
MediaType::from_extension(ext).map(ContentType)
|
MediaType::from_extension(ext).map(ContentType)
|
||||||
}
|
}
|
||||||
);)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! extension {
|
macro_rules! extension {
|
||||||
($($ext:expr => $name:ident,)*) => (
|
($($ext:expr => $name:ident,)*) => (
|
||||||
docify!([
|
/// Returns the most common file extension associated with the
|
||||||
Returns the most common file extension associated with the
|
/// Content-Type `self` if it is known. Otherwise, returns `None`.
|
||||||
@[Content-Type] @code{self} if it is known. Otherwise, returns
|
///
|
||||||
@code{None}. The currently recognized extensions are identical to those
|
/// The currently recognized extensions are identical to those in
|
||||||
in @{"[`ContentType::from_extension()`]"} with the @{"most common"}
|
/// [`ContentType::from_extension()`] with the most common extension
|
||||||
extension being the first extension appearing in the list for a given
|
/// being the first extension appearing in the list for a given
|
||||||
@[Content-Type].
|
/// Content-Type.
|
||||||
];
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// Known extension:
|
/// Known extension:
|
||||||
|
@ -140,23 +144,20 @@ macro_rules! extension {
|
||||||
$(if self == &ContentType::$name { return Some($ext.into()) })*
|
$(if self == &ContentType::$name { return Some($ext.into()) })*
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
);)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! parse_flexible {
|
macro_rules! parse_flexible {
|
||||||
($($short:expr => $name:ident,)*) => (
|
($($short:expr => $name:ident,)*) => (
|
||||||
docify!([
|
/// Flexibly parses `name` into a [`ContentType`]. The parse is
|
||||||
Flexibly parses @code{name} into a @code{ContentType}. The parse is
|
/// _flexible_ because, in addition to strictly correct content types,
|
||||||
@[_flexible_] because, in addition to strictly correct content types, it
|
/// it recognizes the following shorthands:
|
||||||
recognizes the following shorthands:
|
|
||||||
|
|
||||||
@nl
|
|
||||||
$(* $short - @{"`ContentType::"}! @[$name]! @{"`"} @nl)*
|
|
||||||
@nl
|
|
||||||
];
|
|
||||||
///
|
///
|
||||||
/// For regular parsing, use the
|
$(
|
||||||
/// [`ContentType::from_str()`](#impl-FromStr) method.
|
#[doc = concat!("* ", $short, " - [`ContentType::", stringify!($name), "`]")]
|
||||||
|
)*
|
||||||
|
///
|
||||||
|
/// For regular parsing, use [`ContentType::from_str()`].
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
|
@ -205,7 +206,7 @@ macro_rules! parse_flexible {
|
||||||
pub fn parse_flexible(name: &str) -> Option<ContentType> {
|
pub fn parse_flexible(name: &str) -> Option<ContentType> {
|
||||||
MediaType::parse_flexible(name).map(ContentType)
|
MediaType::parse_flexible(name).map(ContentType)
|
||||||
}
|
}
|
||||||
);)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ContentType {
|
impl ContentType {
|
||||||
|
|
|
@ -85,15 +85,13 @@ macro_rules! media_types {
|
||||||
($($name:ident ($check:ident): $str:expr, $t:expr,
|
($($name:ident ($check:ident): $str:expr, $t:expr,
|
||||||
$s:expr $(; $k:expr => $v:expr)*,)+) => {
|
$s:expr $(; $k:expr => $v:expr)*,)+) => {
|
||||||
$(
|
$(
|
||||||
docify!([
|
/// Media Type for
|
||||||
Media Type for @{"**"}! @{$str}! @{"**"}!: @{"`"} @{$t}! @[/]! @{$s}!
|
#[doc = concat!("**", $str, "**: ")]
|
||||||
$(; @{$k}! @[=]! @{$v}!)* @{"`"}!.
|
#[doc = concat!("`", $t, "/", $s, $("; ", $k, "=", $v,)* "`")]
|
||||||
];
|
#[allow(non_upper_case_globals)]
|
||||||
#[allow(non_upper_case_globals)]
|
pub const $name: MediaType = MediaType::new_known(
|
||||||
pub const $name: MediaType = MediaType::new_known(
|
concat!($t, "/", $s, $("; ", $k, "=", $v),*),
|
||||||
concat!($t, "/", $s, $("; ", $k, "=", $v),*),
|
$t, $s, &[$(($k, $v)),*]
|
||||||
$t, $s, &[$(($k, $v)),*]
|
|
||||||
);
|
|
||||||
);
|
);
|
||||||
)+
|
)+
|
||||||
|
|
||||||
|
@ -109,33 +107,32 @@ macro_rules! media_types {
|
||||||
}
|
}
|
||||||
|
|
||||||
$(
|
$(
|
||||||
docify!([
|
/// Returns `true` if the top-level and sublevel types of
|
||||||
Returns @code{true} if the @[top-level] and sublevel types of
|
/// `self` are the same as those of
|
||||||
@code{self} are the same as those of @{"`MediaType::"}! $name
|
#[doc = concat!("`MediaType::", stringify!($name), "`, ")]
|
||||||
@{"`"}!, i.e @{"`"} @{$t}! @[/]! @{$s}! $(; @{$k}! @[=]! @{$v}!)* @{"`"}!.
|
/// i.e
|
||||||
];
|
#[doc = concat!("`", $t, "/", $s, "`.")]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn $check(&self) -> bool {
|
pub fn $check(&self) -> bool {
|
||||||
*self == MediaType::$name
|
*self == MediaType::$name
|
||||||
}
|
}
|
||||||
);
|
|
||||||
)+
|
)+
|
||||||
}}
|
}}
|
||||||
|
|
||||||
macro_rules! from_extension {
|
macro_rules! from_extension {
|
||||||
($($ext:expr => $name:ident,)*) => (
|
($($ext:expr => $name:ident,)*) => (
|
||||||
docify!([
|
/// Returns the Media Type associated with the extension `ext`.
|
||||||
Returns the @[Media-Type] associated with the extension @code{ext}. Not
|
///
|
||||||
all extensions are recognized. If an extensions is not recognized,
|
/// Extensions are matched case-insensitively. Not all extensions are
|
||||||
@code{None} is returned. The currently recognized extensions are:
|
/// recognized. If an extensions is not recognized, `None` is returned.
|
||||||
|
/// The currently recognized extensions are:
|
||||||
@nl
|
///
|
||||||
$(* @{$ext} - @{"`MediaType::"}! @[$name]! @{"`"} @nl)*
|
$(
|
||||||
@nl
|
#[doc = concat!("* ", $ext, " - [`MediaType::", stringify!($name), "`]")]
|
||||||
|
)*
|
||||||
This list is likely to grow. Extensions are matched
|
///
|
||||||
@[case-insensitively.]
|
/// This list is likely to grow.
|
||||||
];
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// Recognized media types:
|
/// Recognized media types:
|
||||||
|
@ -166,19 +163,18 @@ macro_rules! from_extension {
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! extension {
|
macro_rules! extension {
|
||||||
($($ext:expr => $name:ident,)*) => (
|
($($ext:expr => $name:ident,)*) => (
|
||||||
docify!([
|
/// Returns the most common file extension associated with the
|
||||||
Returns the most common file extension associated with the @[Media-Type]
|
/// Media-Type `self` if it is known. Otherwise, returns `None`.
|
||||||
@code{self} if it is known. Otherwise, returns @code{None}. The
|
///
|
||||||
currently recognized extensions are identical to those in
|
/// The currently recognized extensions are identical to those in
|
||||||
@{"[`MediaType::from_extension()`]"} with the @{"most common"} extension
|
/// [`MediaType::from_extension()`] with the most common extension being
|
||||||
being the first extension appearing in the list for a given
|
/// the first extension appearing in the list for a given Content-Type.
|
||||||
@[Media-Type].
|
///
|
||||||
];
|
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// Known extension:
|
/// Known extension:
|
||||||
|
@ -207,22 +203,20 @@ macro_rules! extension {
|
||||||
$(if self == &MediaType::$name { return Some($ext.into()) })*
|
$(if self == &MediaType::$name { return Some($ext.into()) })*
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
);)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! parse_flexible {
|
macro_rules! parse_flexible {
|
||||||
($($short:expr => $name:ident,)*) => (
|
($($short:expr => $name:ident,)*) => (
|
||||||
docify!([
|
/// Flexibly parses `name` into a [`MediaType`]. The parse is
|
||||||
Flexibly parses @code{name} into a @code{MediaType}. The parse is
|
/// _flexible_ because, in addition to strictly correct content types,
|
||||||
@[_flexible_] because, in addition to strictly correct media types, it
|
/// it recognizes the following shorthands:
|
||||||
recognizes the following shorthands:
|
///
|
||||||
|
$(
|
||||||
@nl
|
#[doc = concat!("* ", $short, " - [`MediaType::", stringify!($name), "`]")]
|
||||||
$(* $short - @{"`MediaType::"}! @[$name]! @{"`"} @nl)*
|
)*
|
||||||
@nl
|
///
|
||||||
];
|
/// For regular parsing, use [`MediaType::from_str()`].
|
||||||
/// For regular parsing, use the
|
|
||||||
/// [`MediaType::from_str()`](#impl-FromStr) method.
|
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
|
@ -273,7 +267,7 @@ macro_rules! parse_flexible {
|
||||||
_ => MediaType::from_str(name).ok(),
|
_ => MediaType::from_str(name).ok(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MediaType {
|
impl MediaType {
|
||||||
|
|
|
@ -18,9 +18,6 @@ pub mod hyper;
|
||||||
pub mod uri;
|
pub mod uri;
|
||||||
pub mod ext;
|
pub mod ext;
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
mod docify;
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod header;
|
mod header;
|
||||||
mod method;
|
mod method;
|
||||||
|
|
Loading…
Reference in New Issue