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

Consider making builders chainable

Open dzfranklin opened this issue 2 years ago • 0 comments

That is I want to be able to do

our_feature
   .init_at()
   .set_parent(other_parent)
   .set_idx(other_at)

I think this is possibly arguably only a minor breaking change because most users aren't looking at the unit success type currently returned. One usage I could see this breaking would be users manually writing out error propagation with a match. If that's unacceptable this could be yet another conditional thing in codegen.rs, although the permutations might be getting a bit out of hand there.

Concretely I think this would be implemented by changing the infallible setters from fn set_foo(&mut self, arg: Reader) to fn set_foo(&mut self, arg: Reader) -> &mut Self and the fallible setters to fn set_foo(self, arg: Reader) -> capnp::Result<&mut Self>.

dzfranklin avatar Jun 10 '23 21:06 dzfranklin