Function serde_html_form::from_bytes
source · pub fn from_bytes<'de, T>(input: &'de [u8]) -> Result<T, Error>where
T: Deserialize<'de>,
Expand description
Deserializes a application/x-www-form-urlencoded
value from a &[u8]
.
let meal = vec![
("bread".to_owned(), "baguette".to_owned()),
("cheese".to_owned(), "comté".to_owned()),
("meat".to_owned(), "ham".to_owned()),
("fat".to_owned(), "butter".to_owned()),
];
assert_eq!(
serde_html_form::from_bytes::<Vec<(String, String)>>(
b"bread=baguette&cheese=comt%C3%A9&meat=ham&fat=butter"
),
Ok(meal)
);
Examples found in repository?
src/de.rs (line 65)
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
pub fn from_str<'de, T>(input: &'de str) -> Result<T, Error>
where
T: de::Deserialize<'de>,
{
from_bytes(input.as_bytes())
}
/// Convenience function that reads all bytes from `reader` and deserializes
/// them with `from_bytes`.
pub fn from_reader<T, R>(mut reader: R) -> Result<T, Error>
where
T: de::DeserializeOwned,
R: Read,
{
let mut buf = vec![];
reader
.read_to_end(&mut buf)
.map_err(|e| de::Error::custom(format_args!("could not read input: {}", e)))?;
from_bytes(&buf)
}