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.
Improve guide section on mutations and invocation order for construct…
…ors.
- Loading branch information
1 parent
52d89f8
commit ab45cc3
Showing
18 changed files
with
159 additions
and
25 deletions.
There are no files selected for viewing
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
9 changes: 9 additions & 0 deletions
9
doc_examples/guide/dependency_injection/core_concepts/project-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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
```rust title="src/base/handler.rs" | ||
use super::{A, B}; | ||
use pavex::response::Response; | ||
pub fn handler(a: A, b: B) -> Response { | ||
// Handler logic | ||
// [...] | ||
} | ||
``` |
1 change: 1 addition & 0 deletions
1
doc_examples/guide/dependency_injection/core_concepts/project/.gitignore
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 @@ | ||
/target |
12 changes: 12 additions & 0 deletions
12
doc_examples/guide/dependency_injection/core_concepts/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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "di_core_concepts" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
pavex = { path = "../../../../../libs/pavex" } | ||
pavex_cli_client = { path = "../../../../../libs/pavex_cli_client" } | ||
cargo_px_env = "0.1" | ||
|
||
[workspace] | ||
members = [".", "server_sdk"] |
10 changes: 10 additions & 0 deletions
10
doc_examples/guide/dependency_injection/core_concepts/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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "di_core_concepts_server_sdk" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[package.metadata.px.generate] | ||
generator_type = "cargo_workspace_binary" | ||
generator_name = "di_core_concepts" | ||
|
||
[dependencies] |
Empty file.
11 changes: 11 additions & 0 deletions
11
doc_examples/guide/dependency_injection/core_concepts/project/src/base/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,11 @@ | ||
use pavex::blueprint::Blueprint; | ||
use pavex::blueprint::router::GET; | ||
use pavex::f; | ||
|
||
pub fn blueprint() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.request_scoped(f!(super::a)); | ||
bp.request_scoped(f!(super::b)); | ||
bp.route(GET, "/", f!(super::handler)); | ||
bp | ||
} |
7 changes: 7 additions & 0 deletions
7
doc_examples/guide/dependency_injection/core_concepts/project/src/base/handler.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,7 @@ | ||
use super::{A, B}; | ||
use pavex::response::Response; | ||
|
||
pub fn handler(a: A, b: B) -> Response { | ||
// Handler logic | ||
todo!() | ||
} |
15 changes: 15 additions & 0 deletions
15
doc_examples/guide/dependency_injection/core_concepts/project/src/base/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,15 @@ | ||
pub use blueprint::blueprint; | ||
pub use handler::handler; | ||
|
||
mod blueprint; | ||
mod handler; | ||
|
||
pub struct A; | ||
pub struct B; | ||
|
||
pub fn a() -> A { | ||
A | ||
} | ||
pub fn b() -> B { | ||
B | ||
} |
7 changes: 7 additions & 0 deletions
7
doc_examples/guide/dependency_injection/core_concepts/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,7 @@ | ||
use pavex::blueprint::Blueprint; | ||
|
||
pub fn blueprint() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.nest(crate::base::blueprint()); | ||
bp | ||
} |
7 changes: 7 additions & 0 deletions
7
doc_examples/guide/dependency_injection/core_concepts/project/src/lib.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,7 @@ | ||
#![allow(dead_code)] | ||
#![allow(unused_variables)] | ||
|
||
pub use blueprint::blueprint; | ||
|
||
pub mod base; | ||
mod blueprint; |
14 changes: 14 additions & 0 deletions
14
doc_examples/guide/dependency_injection/core_concepts/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use std::error::Error; | ||
|
||
use cargo_px_env::generated_pkg_manifest_path; | ||
use pavex_cli_client::Client; | ||
|
||
use di_core_concepts::blueprint; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
let generated_dir = generated_pkg_manifest_path()?.parent().unwrap().into(); | ||
Client::new() | ||
.generate(blueprint(), generated_dir) | ||
.execute()?; | ||
Ok(()) | ||
} |
5 changes: 5 additions & 0 deletions
5
doc_examples/guide/dependency_injection/core_concepts/project/src/routes.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 @@ | ||
use pavex::http::StatusCode; | ||
|
||
pub fn handler() -> StatusCode { | ||
todo!() | ||
} |
8 changes: 8 additions & 0 deletions
8
doc_examples/guide/dependency_injection/core_concepts/tutorial.yml
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,8 @@ | ||
starter_project_folder: "project" | ||
commands: | ||
- command: "cargo px c" | ||
expected_outcome: "success" | ||
snippets: | ||
- name: "handler" | ||
source_path: "src/base/handler.rs" | ||
ranges: [ "0..5", "6..8" ] |
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
14 changes: 6 additions & 8 deletions
14
doc_examples/guide/dependency_injection/user_middleware/project-middleware_def.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,18 +1,16 @@ | ||
```rust title="src/authentication.rs" | ||
use std::future::IntoFuture; | ||
use pavex::middleware::Next; | ||
use pavex::middleware::Processing; | ||
use pavex::response::Response; | ||
use crate::user::User; | ||
pub async fn reject_anonymous<C>(user: &User, next: Next<C>) -> Response | ||
where | ||
C: IntoFuture<Output=Response>, | ||
pub fn reject_anonymous(user: &User) -> Processing | ||
{ | ||
if let User::Anonymous = user { | ||
return Response::unauthorized(); | ||
let r = Response::unauthorized(); | ||
Processing::EarlyReturn(r) | ||
} else { | ||
Processing::Continue | ||
} | ||
next.into_future().await | ||
} | ||
``` |
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