1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-18 15:41:17 +00:00

convert from ref string into body

This commit is contained in:
Nikolay Kim 2017-10-29 22:50:21 -07:00
parent 92686b6e1b
commit e3c058c96e

View file

@ -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());