Use lifetimes for more elements of Payload

Text and Bytes can both have their lifetimes parameterized.
This commit is contained in:
Jacob Hoffman-Andrews
2020-10-25 15:52:02 -07:00
parent c8cd130770
commit 17ab5110a3
2 changed files with 12 additions and 7 deletions

View File

@@ -17,11 +17,11 @@ use super::SerdeValue;
/// *Internal API*
pub(crate) enum Payload<'a> {
Empty,
Text(String, String),
Text(&'a str, String),
#[cfg(feature = "json")]
JSON(SerdeValue),
Reader(Box<dyn Read + 'a>),
Bytes(Vec<u8>),
Bytes(&'a [u8]),
}
impl fmt::Debug for Payload<'_> {
@@ -86,7 +86,7 @@ impl<'a> Payload<'a> {
encoding.encode(&text, EncoderTrap::Replace).unwrap()
};
#[cfg(not(feature = "charset"))]
let bytes = text.into_bytes();
let bytes = text.as_bytes();
let len = bytes.len();
let cursor = Cursor::new(bytes);
SizedReader::new(BodySize::Known(len as u64), Box::new(cursor))