I am attempting to create a small grpc service using the tonic framework (but I don't think that should matter here?)
It receives a request and then pings a list of servers which I have stored in a vector and added to my struct
pub struct GRPCServer<'a> {
server_list: Arc<RwLock<Vec<DownStreamServer<'a>>>>,
}
#[tonic::async_trait]
impl grpcservice for GRPCServer<'_>{
...
}
#[derive(Default)]
pub struct DownStreamServer<'a> {
pub host: &'a str,
pub port: u16,
pub protocol: Protocol,
}
Currently I get an error
error[E0726]: implicit elided lifetime not allowed here
--> src/server.rs:27:18
|
27 | impl grpcservice for GRPCServer {
| ^^^^^^^^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>`
and it suggests I add the anonymous lifetime but once I do that it errors on the trait saying lifetime bound not satisfied
I am not too sure where to go from here as it says that
error[E0478]: lifetime bound not satisfied
--> src/server.rs:27:6
|
27 | impl grpcservice for GRPCServer<'_> {
| ^^^^^^^^^^^
|
note: lifetime parameter instantiated with the lifetime `'_` as defined on the impl at 27:36
--> src/server.rs:27:36
|
27 | impl grpcservice for GRPCServer<'_> {
| ^^
= note: but lifetime parameter must outlive the static lifetime
I know that the 'static lifetime is the lifetime that lasts the length of the program but I am not sure of the syntax I should be using to explain that to the compiler
Edit: I think I may have found my answer here
https://stackoverflow.com/questions/59880262/rust-lifetime-parameter-must-outlive-the-static-lifetime
Which I guess means my host value must have a static lifetime?
Would the correct approach be to switch the &str to a String?