Skip to content

Commit

Permalink
add async func in trait support
Browse files Browse the repository at this point in the history
  • Loading branch information
rainj-me committed Nov 9, 2023
1 parent 486c0b1 commit a1756f5
Show file tree
Hide file tree
Showing 25 changed files with 327 additions and 466 deletions.
60 changes: 18 additions & 42 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ members = ["monolake", "monolake-core", "monolake-services"]
resolver = "2"

[workspace.dependencies]
monoio = "0.1.8"
monoio-http = "0.2.4"
monoio-http-client = "0.2.5"
monoio-native-tls = "0.1.0"
monoio-rustls = "0.1.5"
monoio = "0.2.0"
monoio-http = { path = "../monoio-http/monoio-http" }
monoio-http-client = { path = "../monoio-http/monoio-http-client" }
monoio-native-tls = { path = "../monoio-tls/monoio-native-tls" }
monoio-rustls = { path = "../monoio-tls/monoio-rustls" }
native-tls = "0.2"
service-async = "0.1.13"
certain-map = "0.2.4"
service-async = { path = "../service-async/service-async" }
certain-map = { path = "../certain-map/certain-map" }
local-sync = "0.1"

[profile.release-lto]
Expand Down
8 changes: 5 additions & 3 deletions examples/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ entries = 8192

[servers.server_basic]
name = "proxy.monolake.rs"
listener = { type = "socket", value = "0.0.0.0:9081" }
listener = { type = "socket", value = "0.0.0.0:8080" }

[[servers.server_basic.routes]]
path = '/'
upstreams = [{ endpoint = { type = "uri", value = "http://127.0.0.1:8080" }, version = "HTTP2" }]
upstreams = [
{ endpoint = { type = "uri", value = "http://127.0.0.1:9080" }, version = "HTTP2" },
]

[[servers.server_basic.routes]]
path = '/*p'
upstreams = [{ endpoint = { type = "uri", value = "http://127.0.0.1:8080" } }]
upstreams = [{ endpoint = { type = "uri", value = "http://127.0.0.1:9080" } }]


[servers.server_tls]
Expand Down
2 changes: 1 addition & 1 deletion monolake-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "monolake-core"
version = "0.2.0"
version = "0.3.0"
edition = "2021"

[features]
Expand Down
21 changes: 11 additions & 10 deletions monolake-core/src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ pub type HttpAccept<Stream, CX> = (bool, Stream, CX);

pub trait HttpHandler<CX>: SealedT<CX> {
type Error;
type Future<'a>: Future<Output = Result<ResponseWithContinue, Self::Error>>
where
Self: 'a,
CX: 'a;

fn handle(&self, request: Request<HttpBody>, ctx: CX) -> Self::Future<'_>;
fn handle(
&self,
request: Request<HttpBody>,
ctx: CX,
) -> impl Future<Output = Result<ResponseWithContinue, Self::Error>>;
}

impl<T, CX> SealedT<CX> for T where
Expand All @@ -33,11 +33,12 @@ where
T: Service<(Request<HttpBody>, CX), Response = ResponseWithContinue>,
{
type Error = T::Error;
type Future<'a> = impl Future<Output = Result<ResponseWithContinue, Self::Error>> + 'a
where
Self: 'a, CX: 'a;

fn handle(&self, req: Request<HttpBody>, ctx: CX) -> Self::Future<'_> {
self.call((req, ctx))
async fn handle(
&self,
req: Request<HttpBody>,
ctx: CX,
) -> Result<ResponseWithContinue, Self::Error> {
self.call((req, ctx)).await
}
}
3 changes: 0 additions & 3 deletions monolake-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#![feature(impl_trait_in_assoc_type)]
#![feature(type_alias_impl_trait)]

#[macro_use]
mod error;
pub use error::{AnyError, AnyResult};
Expand Down
Loading

0 comments on commit a1756f5

Please sign in to comment.