-
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.
- Loading branch information
1 parent
beb7664
commit 2bd3cc0
Showing
11 changed files
with
92 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod state; |
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,52 @@ | ||
use axum::extract::Request; | ||
use lumx_core::program::Program; | ||
use std::sync::Arc; | ||
use std::task::{Context, Poll}; | ||
use tower::{Layer, Service}; | ||
|
||
#[derive(Clone)] | ||
pub struct StateLayer { | ||
program: Arc<Program>, | ||
} | ||
|
||
impl StateLayer { | ||
pub fn new(program: Arc<Program>) -> Self { | ||
Self { program } | ||
} | ||
} | ||
|
||
impl<S> Layer<S> for StateLayer { | ||
type Service = StateLayerService<S>; | ||
|
||
fn layer(&self, inner: S) -> Self::Service { | ||
StateLayerService { | ||
inner, | ||
program: self.program.clone(), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct StateLayerService<S> { | ||
inner: S, | ||
program: Arc<Program>, | ||
} | ||
|
||
impl<S, B> Service<Request<B>> for StateLayerService<S> | ||
where | ||
S: Service<Request<B>>, | ||
{ | ||
type Response = S::Response; | ||
type Error = S::Error; | ||
type Future = S::Future; | ||
|
||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { | ||
self.inner.poll_ready(cx) | ||
} | ||
|
||
fn call(&mut self, mut req: Request<B>) -> Self::Future { | ||
req.extensions_mut().insert(self.program.clone()); | ||
|
||
self.inner.call(req) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; | ||
|
||
pub fn init() { | ||
tracing_subscriber::registry() | ||
.with( | ||
EnvFilter::try_from_default_env() | ||
.unwrap_or_else(|_| format!("{}=info", env!("CARGO_CRATE_NAME")).into()), | ||
) | ||
.with(fmt::layer()) | ||
.init(); | ||
} |
This file was deleted.
Oops, something went wrong.