diff options
| author | Fuwn <[email protected]> | 2023-04-02 01:28:47 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-04-02 01:28:47 +0000 |
| commit | 63249d1077a6c46da32e468c5c85e97c52115826 (patch) | |
| tree | 2804c348894fb20d3164dc4218b35ef24ca3ba85 | |
| parent | refactor(src): clean up string generics (diff) | |
| download | windmark-63249d1077a6c46da32e468c5c85e97c52115826.tar.xz windmark-63249d1077a6c46da32e468c5c85e97c52115826.zip | |
feat(respones): accept generic bytes for binary_success
| -rw-r--r-- | examples/windmark.rs | 3 | ||||
| -rw-r--r-- | src/response.rs | 4 |
2 files changed, 5 insertions, 2 deletions
diff --git a/examples/windmark.rs b/examples/windmark.rs index ef2813c..4b2b1fc 100644 --- a/examples/windmark.rs +++ b/examples/windmark.rs @@ -186,6 +186,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { router.mount("/file", { windmark::binary_success!(include_bytes!("../LICENSE"), "text/plain") }); + router.mount("/string-file", { + windmark::binary_success!("hi", "text/plain") + }); router.mount( "/secret", Box::new(|context| { diff --git a/src/response.rs b/src/response.rs index c693ac8..6feecf5 100644 --- a/src/response.rs +++ b/src/response.rs @@ -86,10 +86,10 @@ impl Response { #[must_use] pub fn binary_success( - content: &[u8], + content: impl AsRef<[u8]>, mime: impl Into<String> + AsRef<str>, ) -> Self { - Self::new(21, String::from_utf8_lossy(content)) + Self::new(21, String::from_utf8_lossy(content.as_ref())) .with_mime(mime) .clone() } |