Skip to content

Commit

Permalink
chore: renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Dec 23, 2023
1 parent 27b7ebd commit 10a690d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
21 changes: 13 additions & 8 deletions examples/tower/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
use std::{net::SocketAddr, sync::Arc};
use tokio::net::TcpListener;
use tower::util::{MapErrLayer, MapRequestLayer, MapResponseLayer};
use tower::{service_fn, ServiceBuilder};
use tower_http::limit::RequestBodyLimitLayer;
use tower_http::request_id::{MakeRequestUuid, SetRequestIdLayer};
use tower_http::trace::TraceLayer;
use tower::{
service_fn,
util::{MapErrLayer, MapRequestLayer, MapResponseLayer},
ServiceBuilder,
};
use tower_http::{
limit::RequestBodyLimitLayer,
request_id::{MakeRequestUuid, SetRequestIdLayer},
trace::TraceLayer,
};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
use viz::{serve, Body, Error, IntoResponse, Request, Response, Result, Router, Tree};
use viz_tower::{Layered, TowerServiceHandler};
use viz_tower::{Layered, ServiceHandler};

async fn index(_: Request) -> Result<Response> {
Ok("Hello, World!".into_response())
Expand All @@ -36,12 +41,12 @@ async fn main() -> Result<()> {
let index_svc = ServiceBuilder::new()
.layer(MapRequestLayer::new(|req: Request<_>| req.map(Body::wrap)))
.service(service_fn(index));
let index_handler = TowerServiceHandler::new(index_svc);
let index_handler = ServiceHandler::new(index_svc);

let any_svc = ServiceBuilder::new()
.layer(MapResponseLayer::new(IntoResponse::into_response))
.service_fn(any);
let any_handler = TowerServiceHandler::new(any_svc);
let any_handler = ServiceHandler::new(any_svc);

let layer = ServiceBuilder::new()
.layer(TraceLayer::new_for_http())
Expand Down
10 changes: 5 additions & 5 deletions viz-tower/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ pub use middleware::{Layered, Middleware};

/// Converts a tower [`Service`] into a [`Handler`].
#[derive(Debug, Clone)]
pub struct TowerServiceHandler<S>(S);
pub struct ServiceHandler<S>(S);

impl<S> TowerServiceHandler<S> {
/// Creates a new [`TowerServiceHandler`].
impl<S> ServiceHandler<S> {
/// Creates a new [`ServiceHandler`].
pub fn new(s: S) -> Self {
Self(s)
}
}

#[async_trait]
impl<O, S> Handler<Request> for TowerServiceHandler<S>
impl<O, S> Handler<Request> for ServiceHandler<S>
where
O: HttpBody + Send + 'static,
O::Data: Into<Bytes>,
Expand Down Expand Up @@ -102,7 +102,7 @@ mod tests {
.service(hello_svc);

let r0 = Request::new(Body::Full("12".into()));
let h0 = TowerServiceHandler::new(svc);
let h0 = ServiceHandler::new(svc);
assert!(h0.call(r0).await.is_err());

let r1 = Request::new(Body::Full("1".into()));
Expand Down

0 comments on commit 10a690d

Please sign in to comment.