1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! Library for sending and receiving cbox data via axum.
//! Shamelessly copied from JSON part
//! 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.
//!
//! # Extractor example
//!
//! ```rust,no_run
//! use axum::{
//! extract,
//! routing::post,
//! Router,
//! };
//! use serde::Deserialize;
//! use axum_cbor::Cbor;
//!
//! #[derive(Deserialize)]
//! struct CreateUser {
//! email: String,
//! password: String,
//! }
//!
//! async fn create_user(Cbor(payload): Cbor<CreateUser>) {
//! // payload is a `CreateUser`
//! }
//!
//! let app = Router::<()>::new().route("/users", post(create_user));
//! ```
//!
//! When used as a response, it can serialize any type that implements [`serde::Serialize`] to
//! `Cbor`, and will automatically set `content-type: application/cbor`.
//!
//! # Response example
//!
//! ```rust,no_run
//! use axum::{
//! extract::Path,
//! routing::get,
//! Router,
//! };
//! use serde::Serialize;
//! use axum_cbor::Cbor;
//!
//! #[derive(Serialize)]
//! struct User {
//! id: String,
//! username: String,
//! }
//!
//! async fn get_user(Path(user_id) : Path<String>) -> Cbor<User> {
//! let user = find_user(user_id).await;
//! Cbor(user)
//! }
//!
//! async fn find_user(user_id: String) -> User {
//! // ...
//! # unimplemented!()
//! }
//!
//! let app = Router::<()>::new().route("/users/:id", get(get_user));
//! ```
pub use crateCbor;
pub use CborRejection;
pub use *;
pub use ;