data.rs 702 B

12345678910111213141516171819202122232425
  1. use serde::{Deserialize, Serialize};
  2. use std::{fmt, fmt::Formatter};
  3. #[derive(Debug, Serialize, Deserialize)]
  4. pub enum ResponseData {
  5. Bytes(Vec<u8>),
  6. None,
  7. }
  8. impl std::fmt::Display for ResponseData {
  9. fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
  10. match self {
  11. ResponseData::Bytes(bytes) => f.write_fmt(format_args!("{} bytes", bytes.len())),
  12. ResponseData::None => f.write_str("Empty"),
  13. }
  14. }
  15. }
  16. impl std::convert::Into<ResponseData> for String {
  17. fn into(self) -> ResponseData { ResponseData::Bytes(self.into_bytes()) }
  18. }
  19. impl std::convert::Into<ResponseData> for &str {
  20. fn into(self) -> ResponseData { self.to_string().into() }
  21. }