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:
@@ -0,0 +1,20 @@
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use futures::{Stream, StreamExt};
|
||||
use std::sync::Arc;
|
||||
use tonic::{Request, Response, Status};
|
||||
|
||||
tonic::include_proto!("test");
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
struct Svc;
|
||||
|
||||
#[tonic::async_trait]
|
||||
impl test_server::Test for Svc {
|
||||
async fn test_request(
|
||||
self: Arc<Self>,
|
||||
req: Request<SomeData>,
|
||||
) -> Result<Response<SomeData>, Status> {
|
||||
Ok(Response::new(req.into_inner()))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user