You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pub struct GrpcStruct <F>
where
F: tonic::service::interceptor::Interceptor + Clone + Send + Sync + 'static,
{
middleware: Vec<F>,
}
Setting the layer manually is fine
let ss = self.middleware[0].clone();
let ss1 = self.middleware[1].clone();
let ss2 = self.middleware[2].clone();
tonic::transport::Server::builder()
.layer(interceptor(ss))
.layer(interceptor(ss1))
.layer(interceptor(ss2))
.add_service(srv)
.serve(address)
.await
.unwrap();
// But change to dynamic add, will report an error, the error at the bottom
let mut app = tonic::transport::Server::builder();
for mid in self.middleware.iter() {
app = app.layer(interceptor(mid.clone()));
}
app.add_service(srv).serve(address).await.unwrap();
Report an error:
The text was updated successfully, but these errors were encountered:
Middleware in tower is statically typed - so you can't add to it dynamically like this. You might be able to use a lot of boxed services to get around this. See BoxLayer for some inspiration and a better explanation of why this won't work.
Report an error:
The text was updated successfully, but these errors were encountered: