mco_http/json/mod.rs
1use std::io::Read;
2use serde::de::DeserializeOwned;
3use crate::server::Request;
4use crate::error::Result;
5
6pub fn read_json<T: DeserializeOwned>(req: &mut Request) -> Result<T> {
7 let mut json_data = Vec::new();
8 req.read_to_end(&mut json_data)?;
9 Ok(serde_json::from_slice(&json_data).map_err(|e|crate::Error::Other(e.to_string()))?)
10}