allow send_json to send any serde::Serialize value
This commit is contained in:
14
src/body.rs
14
src/body.rs
@@ -7,17 +7,12 @@ use crate::response::DEFAULT_CHARACTER_SET;
|
||||
#[cfg(feature = "charset")]
|
||||
use encoding_rs::Encoding;
|
||||
|
||||
#[cfg(feature = "json")]
|
||||
use super::SerdeValue;
|
||||
|
||||
/// The different kinds of bodies to send.
|
||||
///
|
||||
/// *Internal API*
|
||||
pub(crate) enum Payload<'a> {
|
||||
Empty,
|
||||
Text(&'a str, String),
|
||||
#[cfg(feature = "json")]
|
||||
JSON(SerdeValue),
|
||||
Reader(Box<dyn Read + 'a>),
|
||||
Bytes(&'a [u8]),
|
||||
}
|
||||
@@ -27,8 +22,6 @@ impl fmt::Debug for Payload<'_> {
|
||||
match self {
|
||||
Payload::Empty => write!(f, "Empty"),
|
||||
Payload::Text(t, _) => write!(f, "{}", t),
|
||||
#[cfg(feature = "json")]
|
||||
Payload::JSON(_) => write!(f, "JSON"),
|
||||
Payload::Reader(_) => write!(f, "Reader"),
|
||||
Payload::Bytes(v) => write!(f, "{:?}", v),
|
||||
}
|
||||
@@ -89,13 +82,6 @@ impl<'a> Payload<'a> {
|
||||
let cursor = Cursor::new(bytes);
|
||||
SizedReader::new(BodySize::Known(len as u64), Box::new(cursor))
|
||||
}
|
||||
#[cfg(feature = "json")]
|
||||
Payload::JSON(v) => {
|
||||
let bytes = serde_json::to_vec(&v).expect("Bad JSON in payload");
|
||||
let len = bytes.len();
|
||||
let cursor = Cursor::new(bytes);
|
||||
SizedReader::new(BodySize::Known(len as u64), Box::new(cursor))
|
||||
}
|
||||
Payload::Reader(read) => SizedReader::new(BodySize::Unknown, read),
|
||||
Payload::Bytes(bytes) => {
|
||||
let len = bytes.len();
|
||||
|
||||
Reference in New Issue
Block a user