aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/windmark.rs2
-rw-r--r--src/response/macros.rs32
2 files changed, 33 insertions, 1 deletions
diff --git a/examples/windmark.rs b/examples/windmark.rs
index 4b2b1fc..50914f4 100644
--- a/examples/windmark.rs
+++ b/examples/windmark.rs
@@ -181,7 +181,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
);
#[cfg(feature = "auto-deduce-mime")]
router.mount("/auto-file", {
- windmark::binary_success_auto!(include_bytes!("../LICENSE"))
+ windmark::binary_success!(include_bytes!("../LICENSE"))
});
router.mount("/file", {
windmark::binary_success!(include_bytes!("../LICENSE"), "text/plain")
diff --git a/src/response/macros.rs b/src/response/macros.rs
index e04b0ee..f49da2d 100644
--- a/src/response/macros.rs
+++ b/src/response/macros.rs
@@ -61,9 +61,41 @@ macro_rules! binary_success {
::windmark::Response::binary_success($body, $mime)
})
};
+ ($body:expr) => {{
+ #[cfg(not(feature = "auto-deduce-mime"))]
+ compile_error!(
+ "`binary_success` without a MIME type requires the `auto-deduce-mime` \
+ feature to be enabled"
+ );
+
+ ::std::boxed::Box::new(|_| {
+ #[cfg(feature = "auto-deduce-mime")]
+ return ::windmark::Response::binary_success_auto($body);
+
+ // Suppress item not found warning
+ #[cfg(not(feature = "auto-deduce-mime"))]
+ ::windmark::Response::binary_success($body, "application/octet-stream")
+ })
+ }};
($context:ident, $body:expr, $mime:expr) => {
::std::boxed::Box::new(|$context| {
::windmark::Response::binary_success($body, $mime)
})
};
+ ($context:ident, $body:expr) => {{
+ #[cfg(not(feature = "auto-deduce-mime"))]
+ compile_error!(
+ "`binary_success` without a MIME type requires the `auto-deduce-mime` \
+ feature to be enabled"
+ );
+
+ ::std::boxed::Box::new(|$context| {
+ #[cfg(feature = "auto-deduce-mime")]
+ return ::windmark::Response::binary_success_auto($body);
+
+ // Suppress item not found warning
+ #[cfg(not(feature = "auto-deduce-mime"))]
+ ::windmark::Response::binary_success($body, "application/octet-stream")
+ })
+ }};
}