mirror of
https://github.com/fafhrd91/actix-web
synced 2025-01-18 05:41:50 +01:00
convert from ref string into body
This commit is contained in:
parent
92686b6e1b
commit
e3c058c96e
13
src/body.rs
13
src/body.rs
@ -106,6 +106,12 @@ impl From<String> for BinaryBody {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a String> for BinaryBody {
|
||||
fn from(s: &'a String) -> BinaryBody {
|
||||
BinaryBody::Bytes(Bytes::from(AsRef::<[u8]>::as_ref(&s)))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Bytes> for BinaryBody {
|
||||
fn from(s: Bytes) -> BinaryBody {
|
||||
BinaryBody::Bytes(s)
|
||||
@ -219,6 +225,13 @@ mod tests {
|
||||
assert_eq!(BinaryBody::from(&b).as_ref(), "test".as_bytes());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ref_string() {
|
||||
let b = Rc::new("test".to_owned());
|
||||
assert_eq!(BinaryBody::from(&b).len(), 4);
|
||||
assert_eq!(BinaryBody::from(&b).as_ref(), "test".as_bytes());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rc_string() {
|
||||
let b = Rc::new("test".to_owned());
|
||||
|
Loading…
x
Reference in New Issue
Block a user