forked from LukeMathWalker/pavex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Middleware docs (LukeMathWalker#216)
As it happens, while writing doc examples I uncovered a few more bugs that slipped through the tests I had written so far.
- Loading branch information
1 parent
af78d02
commit d3542f8
Showing
155 changed files
with
2,732 additions
and
781 deletions.
There are no files selected for viewing
30 changes: 0 additions & 30 deletions
30
doc_examples/guide/middleware/core_concepts/project-signalers.snap
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
doc_examples/guide/middleware/core_concepts/project/src/mw.rs
This file was deleted.
Oops, something went wrong.
8 changes: 4 additions & 4 deletions
8
...re_concepts/project-mw_after_handler.snap → ...eware/order/project-mw_after_handler.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
```rust title="src/order2.rs" hl_lines="7 8 9" | ||
```rust title="src/order1/blueprint.rs" hl_lines="9" | ||
use pavex::blueprint::router::GET; | ||
use pavex::blueprint::Blueprint; | ||
use pavex::f; | ||
pub fn blueprint() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.wrap(f!(crate::first)); | ||
bp.route(GET, "/", f!(crate::handler)); | ||
bp.wrap(f!(crate::second)); // (1)! | ||
bp.wrap(f!(crate::wrap1)); | ||
bp.route(GET, "/", f!(super::handler)); | ||
bp.wrap(f!(crate::wrap2)); | ||
bp | ||
} | ||
``` |
8 changes: 4 additions & 4 deletions
8
...ore_concepts/project-mw_after_nested.snap → ...leware/order/project-mw_after_nested.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
```rust title="src/order3.rs" hl_lines="7 8 9" | ||
```rust title="src/order2/blueprint.rs" hl_lines="9" | ||
use pavex::blueprint::router::GET; | ||
use pavex::blueprint::Blueprint; | ||
use pavex::f; | ||
pub fn blueprint() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.wrap(f!(crate::first)); // (1)! | ||
bp.wrap(f!(crate::wrap1)); | ||
bp.nest(nested()); | ||
bp.wrap(f!(crate::second)); // (2)! | ||
bp.wrap(f!(crate::wrap2)); | ||
bp | ||
} | ||
pub fn nested() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.route(GET, "/", f!(crate::handler)); | ||
bp.route(GET, "/", f!(super::handler)); | ||
bp | ||
} | ||
``` |
15 changes: 15 additions & 0 deletions
15
doc_examples/guide/middleware/order/project-post_and_wrap.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
```rust title="src/post_and_wrap/blueprint.rs" | ||
use pavex::blueprint::{Blueprint, router::GET}; | ||
use pavex::f; | ||
pub fn blueprint() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.post_process(f!(crate::post1)); | ||
bp.wrap(f!(crate::wrap1)); | ||
bp.post_process(f!(crate::post2)); | ||
bp.route(GET, "/", f!(super::handler)); | ||
bp | ||
} | ||
``` |
14 changes: 14 additions & 0 deletions
14
doc_examples/guide/middleware/order/project-post_only.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
```rust title="src/post_only/blueprint.rs" | ||
use pavex::blueprint::{Blueprint, router::GET}; | ||
use pavex::f; | ||
pub fn blueprint() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.post_process(f!(crate::post1)); | ||
bp.post_process(f!(crate::post2)); | ||
bp.route(GET, "/", f!(super::handler)); | ||
bp | ||
} | ||
``` |
16 changes: 16 additions & 0 deletions
16
doc_examples/guide/middleware/order/project-pre_and_post.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
```rust title="src/pre_and_post/blueprint.rs" | ||
use pavex::blueprint::{Blueprint, router::GET}; | ||
use pavex::f; | ||
pub fn blueprint() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.pre_process(f!(crate::pre1)); | ||
bp.post_process(f!(crate::post1)); | ||
bp.post_process(f!(crate::post2)); | ||
bp.pre_process(f!(crate::pre2)); | ||
bp.route(GET, "/", f!(super::handler)); | ||
bp | ||
} | ||
``` |
17 changes: 17 additions & 0 deletions
17
doc_examples/guide/middleware/order/project-pre_and_wrap.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
```rust title="src/pre_and_wrap/blueprint.rs" | ||
use pavex::blueprint::{Blueprint, router::GET}; | ||
use pavex::f; | ||
pub fn blueprint() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.pre_process(f!(crate::pre1)); | ||
bp.wrap(f!(crate::wrap1)); | ||
bp.pre_process(f!(crate::pre2)); | ||
bp.wrap(f!(crate::wrap2)); | ||
bp.pre_process(f!(crate::pre3)); | ||
bp.route(GET, "/", f!(super::handler)); | ||
bp | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
```rust title="src/pre_only/blueprint.rs" | ||
use pavex::blueprint::{Blueprint, router::GET}; | ||
use pavex::f; | ||
pub fn blueprint() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.pre_process(f!(crate::pre1)); | ||
bp.pre_process(f!(crate::pre2)); | ||
bp.route(GET, "/", f!(super::handler)); | ||
bp | ||
} | ||
``` |
18 changes: 18 additions & 0 deletions
18
doc_examples/guide/middleware/order/project-registration.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
```rust title="src/core/blueprint.rs" | ||
use pavex::blueprint::router::GET; | ||
use pavex::blueprint::Blueprint; | ||
use pavex::f; | ||
pub fn blueprint() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.pre_process(f!(crate::pre1)); | ||
bp.post_process(f!(crate::post1)); | ||
bp.wrap(f!(crate::wrap1)); | ||
bp.pre_process(f!(crate::pre2)); | ||
bp.post_process(f!(crate::post2)); | ||
bp.route(GET, "/", f!(super::handler)); | ||
bp | ||
} | ||
``` |
14 changes: 14 additions & 0 deletions
14
doc_examples/guide/middleware/order/project-wrap_only.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
```rust title="src/wrap_only/blueprint.rs" | ||
use pavex::blueprint::{Blueprint, router::GET}; | ||
use pavex::f; | ||
pub fn blueprint() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.wrap(f!(crate::wrap1)); | ||
bp.wrap(f!(crate::wrap2)); | ||
bp.route(GET, "/", f!(super::handler)); | ||
bp | ||
} | ||
``` |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ddleware/core_concepts/project/Cargo.toml → ...guide/middleware/order/project/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[package] | ||
name = "mw_core" | ||
name = "order" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
|
4 changes: 2 additions & 2 deletions
4
...re_concepts/project/server_sdk/Cargo.toml → ...eware/order/project/server_sdk/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
[package] | ||
name = "mw_core_server_sdk" | ||
name = "order_server_sdk" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[package.metadata.px.generate] | ||
generator_type = "cargo_workspace_binary" | ||
generator_name = "mw_core" | ||
generator_name = "order" |
File renamed without changes.
15 changes: 15 additions & 0 deletions
15
doc_examples/guide/middleware/order/project/src/blueprint.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use pavex::blueprint::Blueprint; | ||
|
||
pub fn blueprint() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.nest(crate::core::blueprint()); | ||
bp.nest_at("/pre_only", crate::pre_only::blueprint()); | ||
bp.nest_at("/post_only", crate::post_only::blueprint()); | ||
bp.nest_at("/wrap_only", crate::wrap_only::blueprint()); | ||
bp.nest_at("/pre_and_post", crate::pre_and_post::blueprint()); | ||
bp.nest_at("/post_and_wrap", crate::post_and_wrap::blueprint()); | ||
bp.nest_at("/pre_and_wrap", crate::pre_and_wrap::blueprint()); | ||
bp.nest_at("/order1", crate::order1::blueprint()); | ||
bp.nest_at("/order2", crate::order2::blueprint()); | ||
bp | ||
} |
16 changes: 16 additions & 0 deletions
16
doc_examples/guide/middleware/order/project/src/core/blueprint.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use pavex::blueprint::router::GET; | ||
use pavex::blueprint::Blueprint; | ||
use pavex::f; | ||
|
||
pub fn blueprint() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
|
||
bp.pre_process(f!(crate::pre1)); | ||
bp.post_process(f!(crate::post1)); | ||
bp.wrap(f!(crate::wrap1)); | ||
bp.pre_process(f!(crate::pre2)); | ||
bp.post_process(f!(crate::post2)); | ||
bp.route(GET, "/", f!(super::handler)); | ||
|
||
bp | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub use blueprint::blueprint; | ||
pub use routes::handler; | ||
|
||
mod blueprint; | ||
mod routes; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#![allow(dead_code)] | ||
#![allow(unused_variables)] | ||
pub use blueprint::blueprint; | ||
|
||
mod blueprint; | ||
pub mod core; | ||
pub mod order1; | ||
pub mod order2; | ||
pub mod post_only; | ||
pub mod pre_only; | ||
pub mod wrap_only; | ||
pub mod pre_and_post; | ||
pub mod pre_and_wrap; | ||
pub mod post_and_wrap; | ||
mod mw; | ||
pub use mw::*; |
2 changes: 1 addition & 1 deletion
2
...dleware/core_concepts/project/src/main.rs → ...uide/middleware/order/project/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use pavex::middleware::{Next, Processing}; | ||
use pavex::response::Response; | ||
use std::future::IntoFuture; | ||
|
||
pub async fn wrap1<C>(next: Next<C>) -> Response | ||
where | ||
C: IntoFuture<Output = Response>, | ||
{ | ||
next.await | ||
} | ||
|
||
pub async fn wrap2<C>(next: Next<C>) -> Response | ||
where | ||
C: IntoFuture<Output = Response>, | ||
{ | ||
next.await | ||
} | ||
|
||
pub async fn pre1() -> Processing | ||
{ | ||
Processing::Continue | ||
} | ||
|
||
pub async fn pre2() -> Processing | ||
{ | ||
Processing::Continue | ||
} | ||
|
||
pub async fn pre3() -> Processing | ||
{ | ||
Processing::Continue | ||
} | ||
|
||
pub async fn post1(response: Response) -> Response | ||
{ | ||
response | ||
} | ||
|
||
pub async fn post2(response: Response) -> Response | ||
{ | ||
response | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
doc_examples/guide/middleware/order/project/src/order1/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub use blueprint::blueprint; | ||
pub use routes::handler; | ||
|
||
mod blueprint; | ||
mod routes; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
doc_examples/guide/middleware/order/project/src/order2/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub use blueprint::blueprint; | ||
pub use routes::handler; | ||
|
||
mod blueprint; | ||
mod routes; |
File renamed without changes.
Oops, something went wrong.