rocket::serde::msgpack

Type Alias Compact

Source
pub type Compact<T> = MsgPack<T, true>;
Available on crate feature 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

Source§

impl<T, const COMPACT: bool> MsgPack<T, COMPACT>

Source

pub fn into_inner(self) -> T

Consumes the MsgPack wrapper and returns the wrapped item.

§Example
let string = "Hello".to_string();
let my_msgpack: MsgPack<_> = MsgPack(string);
assert_eq!(my_msgpack.into_inner(), "Hello".to_string());

Trait Implementations

Source§

impl<T: Clone, const COMPACT: bool> Clone for MsgPack<T, COMPACT>

Source§

fn clone(&self) -> MsgPack<T, COMPACT>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, const COMPACT: bool> Debug for MsgPack<T, COMPACT>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, const COMPACT: bool> Deref for MsgPack<T, COMPACT>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<T, const COMPACT: bool> DerefMut for MsgPack<T, COMPACT>

Source§

fn deref_mut(&mut self) -> &mut T

Mutably dereferences the value.
Source§

impl<T, const COMPACT: bool> From<T> for MsgPack<T, COMPACT>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash, const COMPACT: bool> Hash for MsgPack<T, COMPACT>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: Ord, const COMPACT: bool> Ord for MsgPack<T, COMPACT>

Source§

fn cmp(&self, other: &MsgPack<T, COMPACT>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq, const COMPACT: bool> PartialEq for MsgPack<T, COMPACT>

Source§

fn eq(&self, other: &MsgPack<T, COMPACT>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd, const COMPACT: bool> PartialOrd for MsgPack<T, COMPACT>

Source§

fn partial_cmp(&self, other: &MsgPack<T, COMPACT>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

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.

Source§

fn respond_to(self, req: &'r Request<'_>) -> Result<'static>

Returns Ok if a Response could be generated successfully. Otherwise, returns an Err with a failing Status. Read more
Source§

impl<T: Eq, const COMPACT: bool> Eq for MsgPack<T, COMPACT>

Source§

impl<T, const COMPACT: bool> StructuralPartialEq for MsgPack<T, COMPACT>