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:
parent
92686b6e1b
commit
e3c058c96e
1 changed files with 13 additions and 0 deletions
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…
Reference in a new issue