pub type Compact<T> = MsgPack<T, true>;
msgpack
only.Expand description
Serializes responses in a compact MesagePack format, where structs are serialized as arrays of their field values.
To respond with compact MessagePack data, return a Compact<T>
type,
where T
implements Serialize
from serde
. The content type of the
response is set to application/msgpack
automatically.
use rocket::serde::msgpack;
#[get("/users/<id>")]
fn user(id: usize) -> msgpack::Compact<User> {
let user_from_id = User::from(id);
/* ... */
msgpack::MsgPack(user_from_id)
}
Prefer using MsgPack<T>
for request guards, as the named/compact
distinction is not relevant for request data - the correct option is
implemented automatically. Using Compact<T>
as a request guard will
NOT prevent named requests from being accepted.
Aliased Type§
struct Compact<T>(pub T);
Fields§
§0: T
Implementations
Trait Implementations
Source§impl<T: Ord, const COMPACT: bool> Ord for MsgPack<T, COMPACT>
impl<T: Ord, const COMPACT: bool> Ord for MsgPack<T, COMPACT>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialOrd, const COMPACT: bool> PartialOrd for MsgPack<T, COMPACT>
impl<T: PartialOrd, const COMPACT: bool> PartialOrd for MsgPack<T, COMPACT>
Source§impl<'r, T: Serialize, const COMPACT: bool> Responder<'r, 'static> for MsgPack<T, COMPACT>
impl<'r, T: Serialize, const COMPACT: bool> Responder<'r, 'static> for MsgPack<T, COMPACT>
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.