Closed aptakhin closed 7 years ago
Self parameter is immutable intentionally. If you need mutable state, you need to store it for example in Arc<Mutex<T>>
:
struct MutableServiceImpl {
value: Arc<Mutex<String>>,
}
impl MutableService for MutableServiceImpl {
fn Set(&self, req: Value) -> GrpcResult<Value> {
*self.value.lock().uwrap() = req.get_value().to_owned();
Ok(Value::new())
}
}
Set
operation can be executed concurrently, so self
should be protected against access from multiple threads.
Cool! It works. Thank you.
And later I saw that it was a duplicate issue, sorry. I'll try to PR some docs here.
No problem, I'm glad to help.
PR is of course always welcome.
Hi Stepan!
Is there a way to change some internal value in service struct? I tried to add
mut
tofn Set(&mut self, req: Value) -> GrpcResult<Value>
signature, but of course it doesn't compiles because generated traits mismatch.Example proto:
Example source: