I don't have much experience with Tonic (or Rust) and I'm trying to figure out the correct pattern for setting up a service. Basically, I have the following code:
Server::builder()
.add_service(MyService::new(some_resource))
.serve(addr)
.await?;
Now the problem with this setup is that MyService must be Send and Sync, which places restrictions on some_resource.
In my current case, some_resource is an RSA key from the tink-core crate. More specifically, what's returned by the following:
https://github.com/project-oak/tink-rust/blob/main/signature/src/verifier_factory.rs#L23
There's really no reason to have a shared resource here, which would cause lock contention. I could just as well have a thread-local RSA key. In other words, how could I use a tink_core::Verifier instance inside a Tonic service without having to protect it by a lock?