From 3e33cfe37c7221850737c4559fc5fb0d0d49aac2 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Fri, 22 Dec 2023 23:42:55 -0800 Subject: [PATCH] Remove custom 'docify!' macro: use '#[doc]`. --- core/http/src/docify.rs | 76 -------------------- core/http/src/header/content_type.rs | 87 +++++++++++------------ core/http/src/header/media_type.rs | 100 +++++++++++++-------------- core/http/src/lib.rs | 3 - 4 files changed, 91 insertions(+), 175 deletions(-) delete mode 100644 core/http/src/docify.rs diff --git a/core/http/src/docify.rs b/core/http/src/docify.rs deleted file mode 100644 index c38d894f..00000000 --- a/core/http/src/docify.rs +++ /dev/null @@ -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)* - }; -} diff --git a/core/http/src/header/content_type.rs b/core/http/src/header/content_type.rs index afa2ede2..f7394ab5 100644 --- a/core/http/src/header/content_type.rs +++ b/core/http/src/header/content_type.rs @@ -44,33 +44,37 @@ use crate::ext::IntoCollection; pub struct ContentType(pub MediaType); 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}! - $(; @{$k}! @[=]! @{$v}!)* @{"`"}!. - ]; - #[allow(non_upper_case_globals)] - pub const $name: ContentType = ContentType(MediaType::$name); - ); + + /// Content Type for + #[doc = concat!("**", $str, "**: ")] + #[doc = concat!("`", $t, "/", $s, $("; ", $k, "=", $v,)* "`")] + + #[allow(non_upper_case_globals)] + pub const $name: ContentType = ContentType(MediaType::$name); )+ }} macro_rules! from_extension { ($($ext:expr => $name:ident,)*) => ( - docify!([ - Returns the @[Content-Type] associated with the extension @code{ext}. - Not all extensions are recognized. If an extensions is not recognized, - @code{None} is returned. The currently recognized extensions are: - - @nl - $(* @{$ext} - @{"`ContentType::"}! @[$name]! @{"`"} @nl)* - @nl - - This list is likely to grow. Extensions are matched - @[case-insensitively.] - ]; + /// Returns the Content-Type associated with the extension `ext`. + /// + /// Extensions are matched case-insensitively. Not all extensions are + /// recognized. If an extensions is not recognized, `None` is returned. + /// The currently recognized extensions are: + /// + $( + #[doc = concat!("* ", $ext, " - [`ContentType::", stringify!($name), "`]")] + )* + /// + /// This list is likely to grow. + /// /// # Example /// /// Recognized content types: @@ -99,19 +103,19 @@ macro_rules! from_extension { pub fn from_extension(ext: &str) -> Option { MediaType::from_extension(ext).map(ContentType) } - );) + ) } macro_rules! extension { ($($ext:expr => $name:ident,)*) => ( - docify!([ - Returns the most common file extension associated with the - @[Content-Type] @code{self} if it is known. Otherwise, returns - @code{None}. The currently recognized extensions are identical to those - in @{"[`ContentType::from_extension()`]"} with the @{"most common"} - extension being the first extension appearing in the list for a given - @[Content-Type]. - ]; + /// Returns the most common file extension associated with the + /// Content-Type `self` if it is known. Otherwise, returns `None`. + /// + /// The currently recognized extensions are identical to those in + /// [`ContentType::from_extension()`] with the most common extension + /// being the first extension appearing in the list for a given + /// Content-Type. + /// /// # Example /// /// Known extension: @@ -140,23 +144,20 @@ macro_rules! extension { $(if self == &ContentType::$name { return Some($ext.into()) })* None } - );) + ) } macro_rules! parse_flexible { ($($short:expr => $name:ident,)*) => ( - docify!([ - Flexibly parses @code{name} into a @code{ContentType}. The parse is - @[_flexible_] because, in addition to strictly correct content types, it - recognizes the following shorthands: - - @nl - $(* $short - @{"`ContentType::"}! @[$name]! @{"`"} @nl)* - @nl - ]; + /// Flexibly parses `name` into a [`ContentType`]. The parse is + /// _flexible_ because, in addition to strictly correct content types, + /// it recognizes the following shorthands: /// - /// 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 /// @@ -205,7 +206,7 @@ macro_rules! parse_flexible { pub fn parse_flexible(name: &str) -> Option { MediaType::parse_flexible(name).map(ContentType) } - );) + ) } impl ContentType { diff --git a/core/http/src/header/media_type.rs b/core/http/src/header/media_type.rs index b764b7da..0d637a81 100644 --- a/core/http/src/header/media_type.rs +++ b/core/http/src/header/media_type.rs @@ -85,15 +85,13 @@ macro_rules! media_types { ($($name:ident ($check:ident): $str:expr, $t:expr, $s:expr $(; $k:expr => $v:expr)*,)+) => { $( - docify!([ - Media Type for @{"**"}! @{$str}! @{"**"}!: @{"`"} @{$t}! @[/]! @{$s}! - $(; @{$k}! @[=]! @{$v}!)* @{"`"}!. - ]; - #[allow(non_upper_case_globals)] - pub const $name: MediaType = MediaType::new_known( - concat!($t, "/", $s, $("; ", $k, "=", $v),*), - $t, $s, &[$(($k, $v)),*] - ); + /// Media Type for + #[doc = concat!("**", $str, "**: ")] + #[doc = concat!("`", $t, "/", $s, $("; ", $k, "=", $v,)* "`")] + #[allow(non_upper_case_globals)] + pub const $name: MediaType = MediaType::new_known( + concat!($t, "/", $s, $("; ", $k, "=", $v),*), + $t, $s, &[$(($k, $v)),*] ); )+ @@ -109,33 +107,32 @@ macro_rules! media_types { } $( - docify!([ - Returns @code{true} if the @[top-level] and sublevel types of - @code{self} are the same as those of @{"`MediaType::"}! $name - @{"`"}!, i.e @{"`"} @{$t}! @[/]! @{$s}! $(; @{$k}! @[=]! @{$v}!)* @{"`"}!. - ]; - #[inline(always)] - pub fn $check(&self) -> bool { - *self == MediaType::$name - } - ); + /// Returns `true` if the top-level and sublevel types of + /// `self` are the same as those of + #[doc = concat!("`MediaType::", stringify!($name), "`, ")] + /// i.e + #[doc = concat!("`", $t, "/", $s, "`.")] + #[inline(always)] + pub fn $check(&self) -> bool { + *self == MediaType::$name + } )+ }} macro_rules! from_extension { ($($ext:expr => $name:ident,)*) => ( - docify!([ - Returns the @[Media-Type] associated with the extension @code{ext}. Not - all extensions are recognized. If an extensions is not recognized, - @code{None} is returned. The currently recognized extensions are: - - @nl - $(* @{$ext} - @{"`MediaType::"}! @[$name]! @{"`"} @nl)* - @nl - - This list is likely to grow. Extensions are matched - @[case-insensitively.] - ]; + /// Returns the Media Type associated with the extension `ext`. + /// + /// Extensions are matched case-insensitively. Not all extensions are + /// recognized. If an extensions is not recognized, `None` is returned. + /// The currently recognized extensions are: + /// + $( + #[doc = concat!("* ", $ext, " - [`MediaType::", stringify!($name), "`]")] + )* + /// + /// This list is likely to grow. + /// /// # Example /// /// Recognized media types: @@ -166,19 +163,18 @@ macro_rules! from_extension { _ => None } } - );) + ) } macro_rules! extension { ($($ext:expr => $name:ident,)*) => ( - docify!([ - Returns the most common file extension associated with the @[Media-Type] - @code{self} if it is known. Otherwise, returns @code{None}. The - currently recognized extensions are identical to those in - @{"[`MediaType::from_extension()`]"} with the @{"most common"} extension - being the first extension appearing in the list for a given - @[Media-Type]. - ]; + /// Returns the most common file extension associated with the + /// Media-Type `self` if it is known. Otherwise, returns `None`. + /// + /// The currently recognized extensions are identical to those in + /// [`MediaType::from_extension()`] with the most common extension being + /// the first extension appearing in the list for a given Content-Type. + /// /// # Example /// /// Known extension: @@ -207,22 +203,20 @@ macro_rules! extension { $(if self == &MediaType::$name { return Some($ext.into()) })* None } - );) + ) } macro_rules! parse_flexible { ($($short:expr => $name:ident,)*) => ( - docify!([ - Flexibly parses @code{name} into a @code{MediaType}. The parse is - @[_flexible_] because, in addition to strictly correct media types, it - recognizes the following shorthands: - - @nl - $(* $short - @{"`MediaType::"}! @[$name]! @{"`"} @nl)* - @nl - ]; - /// For regular parsing, use the - /// [`MediaType::from_str()`](#impl-FromStr) method. + /// Flexibly parses `name` into a [`MediaType`]. The parse is + /// _flexible_ because, in addition to strictly correct content types, + /// it recognizes the following shorthands: + /// + $( + #[doc = concat!("* ", $short, " - [`MediaType::", stringify!($name), "`]")] + )* + /// + /// For regular parsing, use [`MediaType::from_str()`]. /// /// # Example /// @@ -273,7 +267,7 @@ macro_rules! parse_flexible { _ => MediaType::from_str(name).ok(), } } - );) + ) } impl MediaType { diff --git a/core/http/src/lib.rs b/core/http/src/lib.rs index 33a0028e..bdafb283 100644 --- a/core/http/src/lib.rs +++ b/core/http/src/lib.rs @@ -18,9 +18,6 @@ pub mod hyper; pub mod uri; pub mod ext; -#[macro_use] -mod docify; - #[macro_use] mod header; mod method;