pub struct LazyJson<T, const LIMIT: usize = DEFAULT_LIMIT> { /* private fields */ }
Expand description
lazy deserialize type that wrap around Json. It lowers the deserialization to handler function where zero copy deserialize can happen.
§Example
// a json object with zero copy deserialization.
#[derive(Deserialize)]
struct Post<'a> {
title: &'a str,
content: &'a str
}
// handler function utilize Lazy type to lower the Json type into handler function.
async fn handler(lazy: LazyJson<Post<'_>>) -> Result<String, Error> {
// actual deserialize happens here.
let Post { title, content } = lazy.deserialize()?;
// the Post type and it's &str referencing LazyJson would live until the handler
// function return.
Ok(format!("Post {{ title: {title}, content: {content} }}"))
}
App::new()
.at("/post", handler_service(handler))
Implementations§
Source§impl<T, const LIMIT: usize> LazyJson<T, LIMIT>
impl<T, const LIMIT: usize> LazyJson<T, LIMIT>
pub fn deserialize<'de>(&'de self) -> Result<T, Error>where
T: Deserialize<'de>,
Trait Implementations§
Source§impl<'a, 'r, C, B, T, const LIMIT: usize> FromRequest<'a, WebContext<'r, C, B>> for LazyJson<T, LIMIT>
impl<'a, 'r, C, B, T, const LIMIT: usize> FromRequest<'a, WebContext<'r, C, B>> for LazyJson<T, LIMIT>
Auto Trait Implementations§
impl<T, const LIMIT: usize> Freeze for LazyJson<T, LIMIT>
impl<T, const LIMIT: usize> RefUnwindSafe for LazyJson<T, LIMIT>where
T: RefUnwindSafe,
impl<T, const LIMIT: usize> Send for LazyJson<T, LIMIT>where
T: Send,
impl<T, const LIMIT: usize> Sync for LazyJson<T, LIMIT>where
T: Sync,
impl<T, const LIMIT: usize> Unpin for LazyJson<T, LIMIT>where
T: Unpin,
impl<T, const LIMIT: usize> UnwindSafe for LazyJson<T, LIMIT>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more