Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor] config: Use dedicated functions to set options #153

Merged
merged 2 commits into from
May 3, 2023

Conversation

kgraefe
Copy link
Contributor

@kgraefe kgraefe commented Apr 28, 2023

With public members in the config structs the public API breaks each time we're adding new options as the users MUST or MUST NOT add .. Default::default() depending on whether they're setting all options or not. So adding new options breaks for those users who use all options.

This change hides the members from the users and replaces access by dedicated setter functions for each option so adding new options does not break API in the future. (This change obviously is an API break in itself.)

@kgraefe kgraefe force-pushed the refactor-configs branch 2 times, most recently from 9b01c64 to a07fde4 Compare April 28, 2023 07:35
@kgraefe kgraefe changed the title [refactor] config: Replace Default trait by functions [refactor] config: Use dedicated functions to set options Apr 28, 2023
With public members in the config structs the public API breaks each
time we're adding new options as the users MUST or MUST NOT add "..
Default::default()" depending on whether they're setting all options or
not. So adding new options breaks for those users who use all options.

This change hides the members from the users and replaces access by
dedicated setter functions for each option so adding new options does
not break API in the future. (This change obviously is an API break in
itself.)

Signed-off-by: Konrad Gräfe <kgraefe@paktolos.net>
Copy link
Owner

@lemunozm lemunozm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really really like this change and how it's used from the user interface 🚀

Only one ergonomic comment

/// Enables TCP keepalive settings on the socket.
pub keepalive: Option<TcpKeepalive>,
pub fn with_keepalive(mut self, keepalive: TcpKeepalive) -> Self {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would reexport TcpKeepalive type to avoid the user creating a dependency of socket2 only for its usage. Something like:

pub use socket2::TcpKeepalive;

in the top of the file.

Signed-off-by: Konrad Gräfe <kgraefe@paktolos.net>
@kgraefe kgraefe requested a review from lemunozm May 3, 2023 10:02
Copy link
Owner

@lemunozm lemunozm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for this PR 🙌🏻

@lemunozm lemunozm merged commit 73b71a1 into lemunozm:master May 3, 2023
@lemunozm lemunozm mentioned this pull request May 3, 2023
@kgraefe kgraefe deleted the refactor-configs branch May 3, 2023 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants