Error reported for the layer method parameter passing of tonic

use demo_server::{api::demo_server::DemoServer, MyGreeter};
use http::{Request, Response};
use std::{convert::Infallible, time::Duration};
use tonic::{body::BoxBody, server::NamedService, service::Routes, transport::Server};
use tower::Service;
use tower_http::{cors::CorsLayer, timeout::TimeoutLayer, trace::TraceLayer};
use tower_layer::Layer;

#[tokio::main]
async fn main() {
    let trace_layer = TraceLayer::new_for_grpc();
    let cors_layer = CorsLayer::new();
    let time_layer = TimeoutLayer::new(Duration::from_secs(5));

    let layer = tower::ServiceBuilder::new()
        .layer(trace_layer)
        .layer(cors_layer)
        .layer(time_layer)
        .into_inner();

    run(layer).await;
}

async fn run<L>(layer: L)
where
    L: Layer<Routes> + Clone + Send + Sync + 'static,
    L::Service: Service<Request<BoxBody>, Response = Response<BoxBody>, Error = Infallible>
        + NamedService
        + Clone
        + Send
        + Sync
        + 'static,
    <L::Service as Service<Request<BoxBody>>>::Future: Send + Sync + 'static,
{
    let addr = "[::1]:50051".parse().unwrap();
    println!("grpc listening on {}", addr);

    let greeter = MyGreeter::default();
    let svc = DemoServer::new(greeter);

    Server::builder()
        .layer(layer)
        .add_service(svc)
        .serve(addr)
        .await
        .unwrap();
}

The run function definition is fine, but calling run with arguments in main results in an error

Do not post code and errors as an image, it's
unreadable. Paste it as text.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.