tonic-build: option to emit Arc<Self> as server receiver (#1352)

This implements an option to emit `Arc<Self>` instead of `&self` in
server traits. This enables implementor to reference `Self` data for
indefinite duration, which may be useful for streaming requests.

Fixes: #1351
This commit is contained in:
Auri
2023-04-19 19:36:43 +00:00
committed by GitHub
parent 8e506df77e
commit 4942dd4a43
11 changed files with 165 additions and 13 deletions
+6 -2
View File
@@ -337,7 +337,9 @@ pub mod health_server {
request: tonic::Request<super::HealthCheckRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move { (*inner).check(request).await };
let fut = async move {
<T as Health>::check(&inner, request).await
};
Box::pin(fut)
}
}
@@ -382,7 +384,9 @@ pub mod health_server {
request: tonic::Request<super::HealthCheckRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move { (*inner).watch(request).await };
let fut = async move {
<T as Health>::watch(&inner, request).await
};
Box::pin(fut)
}
}