Struct rocket_contrib::msgpack::MsgPack [−][src]
pub struct MsgPack<T>(pub T);
Expand description
The MsgPack
type: implements FromData
and Responder
, allowing you
to easily consume and respond with MessagePack data.
Receiving MessagePack
If you’re receiving MessagePack data, simply add a data
parameter to your
route arguments and ensure the type of the parameter is a MsgPack<T>
,
where T
is some type you’d like to parse from MessagePack. T
must
implement Deserialize
from serde
. The data is parsed from the HTTP
request body.
use rocket_contrib::msgpack::MsgPack; #[post("/users", format = "msgpack", data = "<user>")] fn new_user(user: MsgPack<User>) { /* ... */ }
You don’t need to use format = "msgpack"
, but it may be what you want.
Using format = msgpack
means that any request that doesn’t specify
“application/msgpack” as its first Content-Type:
header parameter will not
be routed to this handler.
Sending MessagePack
If you’re responding with MessagePack data, return a MsgPack<T>
type,
where T
implements Serialize
from serde
. The content type of the
response is set to application/msgpack
automatically.
use rocket_contrib::msgpack::MsgPack; #[get("/users/<id>")] fn user(id: usize) -> MsgPack<User> { let user_from_id = User::from(id); /* ... */ MsgPack(user_from_id) }
Incoming Data Limits
The default size limit for incoming MessagePack data is 1MiB. Setting a
limit protects your application from denial of service (DOS) attacks and
from resource exhaustion through high memory consumption. The limit can be
increased by setting the limits.msgpack
configuration parameter. For
instance, to increase the MessagePack limit to 5MiB for all environments,
you may add the following to your Rocket.toml
:
[global.limits]
msgpack = 5242880
Implementations
impl<T> MsgPack<T>
[src]
impl<T> MsgPack<T>
[src]pub fn into_inner(self) -> T
[src]
pub fn into_inner(self) -> T
[src]Consumes the MsgPack
wrapper and returns the wrapped item.
Example
let string = "Hello".to_string(); let my_msgpack = MsgPack(string); assert_eq!(my_msgpack.into_inner(), "Hello".to_string());
Trait Implementations
impl<'a, T: Deserialize<'a>> FromData<'a> for MsgPack<T>
[src]
impl<'a, T: Deserialize<'a>> FromData<'a> for MsgPack<T>
[src]type Owned = Vec<u8>
type Owned = Vec<u8>
The owned type returned from FromData::transform()
. Read more
type Borrowed = [u8]
type Borrowed = [u8]
The borrowed type consumed by FromData::from_data()
when
FromData::transform()
returns a Transform::Borrowed
. Read more
impl<T: Serialize> Responder<'static> for MsgPack<T>
[src]
impl<T: Serialize> Responder<'static> for MsgPack<T>
[src]Serializes the wrapped value into MessagePack. Returns a response with
Content-Type MsgPack
and a fixed-size body with the serialization. If
serialization fails, an Err
of Status::InternalServerError
is returned.
fn respond_to(self, req: &Request<'_>) -> Result<'static>
[src]
fn respond_to(self, req: &Request<'_>) -> Result<'static>
[src]Returns Ok
if a Response
could be generated successfully. Otherwise,
returns an Err
with a failing Status
. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for MsgPack<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for MsgPack<T> where
T: Send,
T: Send,
impl<T> Sync for MsgPack<T> where
T: Sync,
T: Sync,
impl<T> Unpin for MsgPack<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for MsgPack<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
pub fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
pub fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
Converts self
into a collection.
pub fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where
F: FnMut(T) -> U,
A: Array<Item = U>,
F: FnMut(T) -> U,
A: Array<Item = U>,
impl<T> IntoSql for T
[src]
impl<T> IntoSql for T
[src]fn into_sql<T>(self) -> Self::Expression where
Self: AsExpression<T>,
[src]
fn into_sql<T>(self) -> Self::Expression where
Self: AsExpression<T>,
[src]Convert self
to an expression for Diesel’s query builder. Read more
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
[src]
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
[src]Convert &self
to an expression for Diesel’s query builder. Read more
impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,