First time posting here - enjoying learning Rust thus far I’d like some advice on the idiomatic way to structure applications with stateful values. I’m implementing a system that provides some gRPC APIs, using the grpcio crate. With this frame, I have some questions about lifetimes and stateful values.
The way the protobuf generated code is, one has to make a struct and then implement a trait (simple enough). I’m able to propagate pure values down into the generated gRPC services, but stateful values are proving more difficult as they obviously won’t Copy. Instead, I started by passing in references, which required lifetimes on the
Whilst this allowed usage of the value at the points needed, I encountered problems with the lifetime checker when trying to tie the knot at the top of the function chain:
As the function being called here is generated from the proto files, I cannot control the types or lifetimes being specified. Best I can tell at this point, the only option would be to use something like the
lazy_const crate and treat the stateful value (which happens to be a network client with connection pool) and then treat said value as global? If there are alternate (or better) ways to of doing this kind of thing, without global state, that would be great to hear about.
Thanks for any advice in advance!