[−][src]Struct rocket_contrib::msgpack::MsgPack
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
Methods
impl<T> MsgPack<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<T> DerefMut for MsgPack<T>
[src]
impl<T> Deref for MsgPack<T>
[src]
impl<T: Debug> Debug for MsgPack<T>
[src]
impl<'a, T: Deserialize<'a>> FromData<'a> for MsgPack<T>
[src]
type Error = Error
The associated error to be returned when the guard fails.
type Owned = Vec<u8>
The owned type returned from [FromData::transform()
]. Read more
type Borrowed = [u8]
The borrowed type consumed by [FromData::from_data()
] when [FromData::transform()
] returns a [Transform::Borrowed
]. Read more
fn transform(
r: &Request,
d: Data
) -> Transform<Outcome<Self::Owned, Self::Error>>
[src]
r: &Request,
d: Data
) -> Transform<Outcome<Self::Owned, Self::Error>>
fn from_data(
_: &Request,
o: Transformed<'a, Self>
) -> Outcome<Self, Self::Error>
[src]
_: &Request,
o: Transformed<'a, Self>
) -> Outcome<Self, Self::Error>
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, _: &Request) -> Result<'static>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Typeable for T where
T: Any,
T: Any,
impl<'a, T> FromData<'a> for T where
T: FromDataSimple,
[src]
T: FromDataSimple,
type Error = <T as FromDataSimple>::Error
The associated error to be returned when the guard fails.
type Owned = Data
The owned type returned from [FromData::transform()
]. Read more
type Borrowed = Data
The borrowed type consumed by [FromData::from_data()
] when [FromData::transform()
] returns a [Transform::Borrowed
]. Read more
fn transform(
&Request,
d: Data
) -> Transform<Outcome<<T as FromData<'a>>::Owned, (Status, <T as FromData<'a>>::Error), Data>, Outcome<<T as FromData<'a>>::Owned, (Status, <T as FromData<'a>>::Error), Data>>
[src]
&Request,
d: Data
) -> Transform<Outcome<<T as FromData<'a>>::Owned, (Status, <T as FromData<'a>>::Error), Data>, Outcome<<T as FromData<'a>>::Owned, (Status, <T as FromData<'a>>::Error), Data>>
fn from_data(
req: &Request,
o: Transform<Outcome<<T as FromData<'a>>::Owned, (Status, <T as FromData<'a>>::Error), Data>, Outcome<&'a <T as FromData<'a>>::Borrowed, (Status, <T as FromData<'a>>::Error), Data>>
) -> Outcome<T, (Status, <T as FromData<'a>>::Error), Data>
[src]
req: &Request,
o: Transform<Outcome<<T as FromData<'a>>::Owned, (Status, <T as FromData<'a>>::Error), Data>, Outcome<&'a <T as FromData<'a>>::Borrowed, (Status, <T as FromData<'a>>::Error), Data>>
) -> Outcome<T, (Status, <T as FromData<'a>>::Error), Data>
impl<T> IntoCollection<T> for T
fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
A: Array<Item = T>,
fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where
A: Array<Item = U>,
F: FnMut(T) -> U,
A: Array<Item = U>,
F: FnMut(T) -> U,
impl<T, I> AsResult<T, I> for T where
I: Input,
I: Input,
impl<T> Erased for T
impl<T> IntoSql for T
[src]
fn into_sql<T>(self) -> Self::Expression where
Self: AsExpression<T>,
[src]
Self: AsExpression<T>,
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]
&'a Self: AsExpression<T>,
Convert &self
to an expression for Diesel's query builder. Read more
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
U: TryFrom<T>,