facet_axum/
lib.rs

1//! Axum integration for Facet.
2//!
3//! This crate provides Axum extractors and response types that use Facet's
4//! serialization instead of serde. This allows you to use Facet-derived types
5//! directly in your Axum handlers without needing serde derives.
6//!
7//! # Features
8//!
9//! - `json` (default): Enables `Json<T>` extractor/response using `facet-json`
10//! - `form` (default): Enables `Form<T>` and `Query<T>` extractors using `facet-urlencoded`
11//!
12//! # Example
13//!
14//! ```ignore
15//! use axum::{routing::{get, post}, Router};
16//! use facet::Facet;
17//! use facet_axum::{Json, Query};
18//!
19//! #[derive(Debug, Facet)]
20//! struct CreateUser {
21//!     name: String,
22//!     email: String,
23//! }
24//!
25//! #[derive(Debug, Facet)]
26//! struct User {
27//!     id: u64,
28//!     name: String,
29//!     email: String,
30//! }
31//!
32//! #[derive(Debug, Facet)]
33//! struct SearchParams {
34//!     q: String,
35//!     page: u64,
36//! }
37//!
38//! async fn create_user(Json(payload): Json<CreateUser>) -> Json<User> {
39//!     Json(User {
40//!         id: 1,
41//!         name: payload.name,
42//!         email: payload.email,
43//!     })
44//! }
45//!
46//! async fn search(Query(params): Query<SearchParams>) -> String {
47//!     format!("Searching for '{}' on page {}", params.q, params.page)
48//! }
49//!
50//! let app = Router::new()
51//!     .route("/users", post(create_user))
52//!     .route("/search", get(search));
53//! ```
54
55#![warn(missing_docs)]
56
57// Re-export JSON types
58#[cfg(feature = "json")]
59pub use facet_json::{Json, JsonRejection};
60
61// Re-export form/query types
62#[cfg(feature = "form")]
63pub use facet_urlencoded::{Form, FormRejection, Query, QueryRejection};
64
65// Re-export YAML types
66#[cfg(feature = "yaml")]
67pub use facet_yaml::{Yaml, YamlRejection};
68
69// Re-export TOML types
70#[cfg(feature = "toml")]
71pub use facet_toml::{Toml, TomlRejection};
72
73// Re-export XML types
74#[cfg(feature = "xml")]
75pub use facet_xml::{Xml, XmlRejection};
76
77// Re-export MessagePack types
78#[cfg(feature = "msgpack")]
79pub use facet_msgpack::{MsgPack, MsgPackRejection};
80
81// Re-export Postcard types
82#[cfg(feature = "postcard")]
83pub use facet_postcard::{Postcard, PostcardRejection};