-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b6c8fb5
commit 8ff93b0
Showing
9 changed files
with
154 additions
and
195 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
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
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,4 +1,8 @@ | ||
mod parts; | ||
mod state; | ||
mod path; | ||
|
||
pub use state::{State, StateError}; | ||
|
||
use crate::IntoResponse; | ||
|
||
|
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,37 @@ | ||
use astra::Body; | ||
use http::StatusCode; | ||
|
||
use crate::{FromRequest, IntoResponse}; | ||
|
||
#[derive(Debug)] | ||
pub struct Path<T>(pub T); | ||
|
||
impl<T> FromRequest for Path<T> | ||
where | ||
T: Send + Sync + 'static, | ||
{ | ||
type Error = PathError; | ||
|
||
fn from_request(_request: &mut astra::Request) -> Result<Self, Self::Error> { | ||
todo!() | ||
} | ||
} | ||
|
||
pub struct PathError {} | ||
|
||
impl IntoResponse for PathError { | ||
fn into_response(self) -> astra::Response { | ||
astra::ResponseBuilder::new() | ||
.status(StatusCode::BAD_REQUEST) | ||
.body(Body::empty()) | ||
.unwrap() | ||
} | ||
} | ||
|
||
impl<T> std::ops::Deref for Path<T> { | ||
type Target = T; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} |
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,28 @@ | ||
use crate::{FromRequest, IntoResponse}; | ||
use astra::{Body, Response, ResponseBuilder}; | ||
use http::StatusCode; | ||
|
||
#[derive(Debug, Default, Clone, Copy)] | ||
pub struct State<T>(T); | ||
|
||
impl<T> FromRequest for State<T> | ||
where | ||
T: Clone + Send + Sync + 'static, | ||
{ | ||
type Error = StateError; | ||
|
||
fn from_request(request: &mut astra::Request) -> Result<Self, Self::Error> { | ||
request.extensions().get().cloned().ok_or(StateError) | ||
} | ||
} | ||
|
||
pub struct StateError; | ||
|
||
impl IntoResponse for StateError { | ||
fn into_response(self) -> Response { | ||
ResponseBuilder::new() | ||
.status(StatusCode::INTERNAL_SERVER_ERROR) | ||
.body(Body::empty()) | ||
.unwrap() | ||
} | ||
} |
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,11 @@ | ||
pub mod handler; | ||
|
||
mod extract; | ||
mod layer; | ||
mod response; | ||
mod router; | ||
mod server; | ||
mod layer; | ||
|
||
pub use extract::FromRequest; | ||
pub use layer::{layer_fn, Layer, Next}; | ||
pub use response::IntoResponse; | ||
pub use router::Group; | ||
pub use server::Router; | ||
pub use layer::{layer_fn, Next, Layer}; | ||
pub use router::Router; |
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
Oops, something went wrong.