Merge pull request #48 from emschwartz/master

feat: impl Into<Vec<u8>> for Message
pull/52/head
Alexey Galakhov 6 years ago committed by GitHub
commit 4c8d64de12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      src/protocol/message.rs

@ -303,6 +303,12 @@ impl From<Vec<u8>> for Message {
}
}
impl Into<Vec<u8>> for Message {
fn into(self) -> Vec<u8> {
self.into_data()
}
}
impl fmt::Display for Message {
fn fmt(&self, f: &mut fmt::Formatter) -> StdResult<(), fmt::Error> {
if let Ok(string) = self.to_text() {
@ -343,6 +349,15 @@ mod tests {
assert!(msg.into_text().is_err());
}
#[test]
fn binary_convert_into_vec() {
let bin = vec![6u8, 7, 8, 9, 10, 241];
let bin_copy = bin.clone();
let msg = Message::from(bin);
let serialized: Vec<u8> = msg.into();
assert_eq!(bin_copy, serialized);
}
#[test]
fn text_convert() {
let s = "kiwotsukete";

Loading…
Cancel
Save