1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 14:49:20 +02:00

Add responder impl for Cow<str> (#2164)

This commit is contained in:
fakeshadow
2021-04-15 16:54:51 -07:00
committed by GitHub
parent 64bed506c2
commit 845c02cb86
2 changed files with 57 additions and 44 deletions

View File

@ -1,4 +1,5 @@
use std::{
borrow::Cow,
fmt, mem,
pin::Pin,
task::{Context, Poll},
@ -118,12 +119,23 @@ impl From<String> for Body {
}
}
impl<'a> From<&'a String> for Body {
fn from(s: &'a String) -> Body {
impl From<&'_ String> for Body {
fn from(s: &String) -> Body {
Body::Bytes(Bytes::copy_from_slice(AsRef::<[u8]>::as_ref(&s)))
}
}
impl From<Cow<'_, str>> for Body {
fn from(s: Cow<'_, str>) -> Body {
match s {
Cow::Owned(s) => Body::from(s),
Cow::Borrowed(s) => {
Body::Bytes(Bytes::copy_from_slice(AsRef::<[u8]>::as_ref(s)))
}
}
}
}
impl From<Bytes> for Body {
fn from(s: Bytes) -> Body {
Body::Bytes(s)