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

Impl core::error::Error instead of std::error::Error #333

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DeppLearning
Copy link

Hey there,

thanks for the great library! I noticed that the Error trait is not implemented for BuilderErrors when the std feature is inactive. Rust 1.81 stabilized core::error::Error, it would be nice if this crate could make use of it and lift the former restriction. Since, as implemented, this would be a breaking change, I'm wondering what the preferred way forward is. I can think of

  • add a feature flag, like core_error that opts into using core::error::Error instead of the std version
  • use something like https://crates.io/crates/rustversion/ to gate the core version behind a #[rustversion::since(1.81)]
  • others?

@TedDriggs
Copy link
Collaborator

add a feature flag, like core_error that opts into using core::error::Error instead of the std version

I think I'd rather bump the MSRV than use a cargo flag for it. If the only difference between 0.20.x and 0.21.0 is an MSRV bump for this purpose, upgrading will be very easy for those who can upgrade, and those who can't upgrade won't be missing out on anything.

use something like https://crates.io/crates/rustversion/ to gate the core version behind a #[rustversion::since(1.81)]

I wouldn't consider a version that included rustversion in the generated code, but would be willing to have the derive_builder_core crate take that dependency. Would the code in the macro be something like...

if rustversion::cfg!(since(1.81)) {
    // generate core::error::Error impl
}

@@ -294,11 +295,9 @@ impl<'a> ToTokens for Builder<'a> {
}
));

if self.std {
tokens.append_all(quote!(
impl std::error::Error for #builder_error_ident {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

In ≥1.81, is there some blanket impl on std::error::Error that means all core::error::Error impls are satisfactory? If not, do we need to emit both impls to avoid breaking compatibility?

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