Skip to content

Commit ec105fd

Browse files
committed
test: Test code in README.md
1 parent 5014cfc commit ec105fd

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Typed accept negotiation for axum, following [RFC7231](https://www.rfc-editor.or
1212
```rust
1313
use axum::{extract::Json, response::{IntoResponse, Response}};
1414
use axum_accept::AcceptExtractor;
15-
use serde::Serialize;
1615
use serde_json::json;
1716

1817
#[derive(AcceptExtractor)]
@@ -25,8 +24,8 @@ enum Accept {
2524

2625
async fn my_handler(accept: Accept) -> Response {
2726
match accept {
28-
TextPlain => "hello world".into_response(),
29-
ApplicationJson => Json(json! { "content": "hello_world".to_string() }).into_response(),
27+
Accept::TextPlain => "hello world".into_response(),
28+
Accept::ApplicationJson => Json(json!({ "content": "hello_world" })).into_response(),
3029
}
3130
}
3231
```

axum-accept/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ axum-accept-macros= { version = "0.0.2", path = "../axum-accept-macros" }
1414
axum-accept-shared = { version = "0.0.2", path = "../axum-accept-shared" }
1515

1616
[dev-dependencies]
17-
axum = { workspace = true }
17+
axum = { workspace = true, features = ["json"] }
18+
serde_json = "1"
1819
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

axum-accept/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
pub use axum_accept_macros::AcceptExtractor;
1818
pub use axum_accept_shared::AcceptRejection;
1919

20+
#[cfg(doctest)]
21+
#[doc = include_str!("../../README.md")]
22+
pub struct ReadmeDoctests;
23+
2024
#[cfg(test)]
2125
mod tests {
2226
use super::*;

0 commit comments

Comments
 (0)