capnproto-rust icon indicating copy to clipboard operation
capnproto-rust copied to clipboard

accepting reference instead of value

Open b00f opened this issue 5 years ago • 2 comments

If you look at the calculator example, function client needs to be passed by value to setter methods. This causes that the object became invalid for the next use. Therefore we need to clone the object. Is it possible to pass them by reference not value?

https://github.com/capnproto/capnproto-rust/blob/8af305247921c4ede4fb21f8dfeef3f7ee6f3ba3/capnp-rpc/examples/calculator/client.rs#L189

b00f avatar May 29 '20 04:05 b00f

The clone() call is not a deep copy -- it just increases the reference count, similar to Rc<T>.

We could make the generated set_foo() methods take their argument by reference. That might be less annoying for callers, but it would mean such methods would need to call clone() internally, even if there is no actual need to increase the reference count. So my preference is to keep things how they are.

dwrensha avatar May 29 '20 22:05 dwrensha

I fully understand the difficulties that you have as an author (Rust is like a nagging wife and you can't do what ever you want!). In the other side, a user of this library may ask why should I pass this variable by value while I may need it later. Maybe you can think about the 3rd solution when you are stuck between two bad ideas.

Probably it can be linked to #179

b00f avatar May 31 '20 05:05 b00f