Struct cocaine::Response [−][src]
pub struct Response<'a: 'b, 'b> { /* fields omitted */ }
Generic response type.
Methods
impl<'a: 'b, 'b> Response<'a, 'b>
[src]
impl<'a: 'b, 'b> Response<'a, 'b>
pub fn ty(&self) -> u64
[src]
pub fn ty(&self) -> u64
Returns a response type.
pub fn deserialize<T: Deserialize<'b>>(&self) -> Result<T, Error>
[src]
pub fn deserialize<T: Deserialize<'b>>(&self) -> Result<T, Error>
Deserializes the response into the specified type.
Note, that this method can also be used to deserialize a response into some borrowed type,
like &str
, &[u8]
or into an user-defined type that contains them. In this case the
deserialization is completely zero-copy.
Errors
This method can fail if the underlying deserializer decides to fail.
Examples
This example demonstrates how to use deserialization into a borrowed struct.
use cocaine::{Error, Response}; #[derive(Debug, Deserialize)] struct User<'a> { name: &'a str, age: u16, } fn handle(resp: &Response) -> Result<(), Error> { let user: User = resp.deserialize()?; println!("User: {:?}", user); Ok(()) }
pub fn headers(&self) -> &[HeaderRef]
[src]
pub fn headers(&self) -> &[HeaderRef]
Returns response headers.