API improvement to allow fluent calls
pm100 opened this issue · 1 comments
pm100 commented
A few improvements having used it myself in a non-trivial project
make all the setters return &Self. This allows fluent use
ie instead of
textarea.set_block(
Block::default()
.borders(Borders::ALL)
.title("Crossterm Minimal Example"),
);
textarea.set_hard_tab_indent(true);
have
textarea.set_block(
Block::default()
.borders(Borders::ALL)
.title("Crossterm Minimal Example"),
).set_hard_tab_indent(true)
.set_mask_char('*');
this is common practice in rust crates with many setters
rhysd commented
Thanks for your suggestion. But I think the current setter interfaces are better because:
- It looks like builder, but
TextArea
is actually not a builder. - Responsibility of setter method is setting some state. And it should not do other things. So returning nothing is the most assumed interface (especially by readers of source code).
- I don't see much benefit on this interface. It can remove a repeat of receiver. But it only saves a few key strokes.