use bytes::Bytes; use std::{fmt, fmt::Formatter}; pub enum PayloadError {} // TODO: support stream data #[derive(Clone, Debug, serde::Serialize)] pub enum Payload { None, Bytes(Vec), } impl std::fmt::Display for Payload { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { Payload::Bytes(bytes) => f.write_fmt(format_args!("{} bytes", bytes.len())), Payload::None => f.write_str("Empty"), } } } impl std::convert::Into for String { fn into(self) -> Payload { Payload::Bytes(self.into_bytes()) } } impl std::convert::Into for &'_ String { fn into(self) -> Payload { Payload::Bytes(self.to_owned().into_bytes()) } } impl std::convert::Into for Bytes { fn into(self) -> Payload { // Opti(nathan): do not copy the bytes? Payload::Bytes(self.as_ref().to_vec()) } } impl std::convert::Into for Vec { fn into(self) -> Payload { Payload::Bytes(self) } } impl std::convert::Into for &str { fn into(self) -> Payload { self.to_string().into() } }