Skip to content

Non exhaustive #24

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

Merged
merged 1 commit into from
Sep 2, 2021
Merged

Non exhaustive #24

merged 1 commit into from
Sep 2, 2021

Conversation

RCasatta
Copy link
Collaborator

@RCasatta RCasatta commented Sep 1, 2021

fix #21

on top of #22

@RCasatta RCasatta marked this pull request as draft September 1, 2021 12:05
@RCasatta
Copy link
Collaborator Author

RCasatta commented Sep 1, 2021

It looks this cause trouble if downstream crates use

let conf = bitcoind::Conf {
            view_stdout: true,
            ..Default::default()
        };
error[E0639]: cannot create non-exhaustive struct using struct expression

@RCasatta RCasatta marked this pull request as ready for review September 2, 2021 06:34
@RCasatta
Copy link
Collaborator Author

RCasatta commented Sep 2, 2021

Given that the syntax ....Default::default() it's not supported with non-exhaustive, so user's code should do something like:

let mut conf = bitcoind::Conf::default();
conf.view_stdout = true;

Is this desirable for end-users? Or it's better to not have this (and non_exhaustive) at the cost of breaking downstream when new parameters are added?

I think non_exhaustive is still desirable (maybe coupled with a builder pattern)
What @LeoComandini @LLFourn @rajarshimaitra think?

@LeoComandini
Copy link
Collaborator

utACK df37667, I think non_exhaustive is desirable

@RCasatta RCasatta merged commit df37667 into master Sep 2, 2021
@Kixunil
Copy link

Kixunil commented Sep 6, 2021

FYI from my experience for library users it's usually most convenient to use builder pattern which moves self. Although this is arguably annoying to implement. I think there's a proc macro for that.

I think it'd be perfect if either we could do non_exhaustive with ..Default::default() or have some sort of default constructor and then struct initialization syntax just overwrites the fields.

@RCasatta RCasatta deleted the non_exhaustive branch January 18, 2022 09:14
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.

use #[non_exhaustive] for config
3 participants