pub struct Cbor<T>(pub T);Expand description
CBOR Extractor / Response.
When used as an extractor, it can deserialize request bodies into some type that
implements serde::Deserialize. The request will be rejected (and a CborRejection will
be returned) if:
- The request doesn’t have a
Content-Type: application/cbor(or similar) header. - The body doesn’t contain syntactically valid CBOR.
- The body contains syntactically valid CBOR but it couldn’t be deserialized into the target type.
- Buffering the request body fails.
⚠️ Since parsing CBOR requires consuming the request body, the Cbor extractor must be
last if there are multiple extractors in a handler.
See “the order of extractors”
Tuple Fields§
§0: TImplementations§
Source§impl<T> Cbor<T>where
T: DeserializeOwned,
impl<T> Cbor<T>where
T: DeserializeOwned,
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, CborRejection>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, CborRejection>
Construct a Cbor<T> from a byte slice.
This method attempts to deserialize the provided bytes as CBOR data.
Returns a CborRejection if deserialization fails.
Trait Implementations§
Source§impl<S, T> FromRequest<S> for Cbor<T>
impl<S, T> FromRequest<S> for Cbor<T>
Source§async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection>
async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection>
Extract a CBOR payload from the request body.
This implementation validates the content type and deserializes the CBOR data.
Returns a CborRejection if validation or deserialization fails.
Source§type Rejection = CborRejection
type Rejection = CborRejection
Source§impl<T> IntoResponse for Cbor<T>where
T: Serialize,
impl<T> IntoResponse for Cbor<T>where
T: Serialize,
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Convert the CBOR payload into an HTTP response.
This serializes the inner value to CBOR format and sets the appropriate
Content-Type: application/cbor header. Returns a 500 Internal Server Error
if serialization fails.