containerd / ttrpc-rust

Rust implementation of ttrpc (GRPC for low-memory environments)
Apache License 2.0
197 stars 47 forks source link

unmutable self for generated server trait methods #73

Closed sjames closed 3 years ago

sjames commented 3 years ago

Description of problem

The generated server trait uses a &self. Method calls coming into the server can modify state. It is not currently possible to modify state due to the &self. I believe this should be &mut self for the server trait.

Expected result

The generated trait functions for the server should use &mut self.

Actual result

The generated trait functions for the server uses &self.

teawater commented 3 years ago

@Tim-Zhang

Tim-Zhang commented 3 years ago

Hi @sjames,

The change will cause the incompatible and we did not encounter similar needs

Can you provied more information, why do you need this?

sjames commented 3 years ago

I want to modify the members of the structure when handling the server functions. It would have been convenient to have a mutable self so I could mutate the members.

I worked around this by creating an inner struct of type inner std::sync::Arc<std::sync::RwLock<Inner>>

I can mutate the contents of inner after taking a write lock. Perhaps this is indeed the right way to do it. I suggest you can close the ticket.

Thank you, Regards, Sojan

Tim-Zhang commented 3 years ago

OK