-
Notifications
You must be signed in to change notification settings - Fork 30
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
Cannot derive DbEnum when schema.rs is separated into different crates #93
Comments
IIRC Clone bound is sometimes necessary around boxed expressions and/or joins within Diesel. (If I added it it's surely because my own project didn't compile without and it was present before) As far as I know it is true that it's now possible to add this implementation via this diesel.toml configuration instead. However since this is probably typically not set for existing projects or even the default for new projects (https://github.com/diesel-rs/diesel/blob/ce16e91bea0bd85342ff1cf1d683a8b8cb1a6ffc/diesel_cli/src/default_files/diesel.toml#L6) I don't think it would be reasonable to by default not generate it, as that would be a significant breaking change. Also I think diesel would probably accept to add the clone bound as a default in the default diesel.toml of the cli if you were to PR that there. Once that is released maybe changing the behavior of this crate would make more sense but it would still seem difficult to release it as non breaking. That being said as far as I'm concerned I also have separate schema crates and I define my DbEnums in the same crate as I define my schema and I have no issue, and it also looks like it works better if several crates depend on the schema crate. |
Thanks, really useful info. I agree that we can't wholesale remove the Alternatively could have
This does sound like the most practical solution |
I was thinking adding an attribute rather, since this is pretty edge-casey. It allows the thing, just makes it slightly more verbose. (But not sure that's worth the added complexity considering the available alternate solution) |
Thank you for considering my proposal. My project is separated into three workspaces.
The dependencies between crates are as follows: The Indeed, as you said, I think this is a pretty edge case. However, depending on the situation where diesel is used, clone-impl may not be necessary, so whether clone-impl is necessary or not depends on the situation.
I got the feeling that the solution is not a very good solution. Maybe the only solution is to define the DbEnum within the same crate? |
That does seem like a legit use-case. I think the best solution is to:
|
thank you for your reply.
Is it better to add DbEnum attribute instead of feature flag? #[derive(diesel_derive_enum::DbEnum)]
#[NoClone]
pub enum SomeEnum {
A,
B,
} Does it look like the above? |
I think so, for the reason that features generally should generally be additive (enabling a feature should not break existing code), and this is still edge-case enough that we probably don't want to break that rule
The convention is generally to use snake_case for attributes but it seems so far in this crate we're using Pascal (e.g. #[derive(diesel_derive_enum::DbEnum, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[DontImplCloneOnSqlType]
pub enum SomeEnum {
A,
B,
} Then it's just about passing Line 204 in 36c44a2
|
Thank you. I will consider how to fix. |
Because, if schema definitions are separated into other crate, implementing Clone for ExistingType will happen compile error. cf. adwhit#93 # Please enter the commit message for your changes. Lines starting
Because, if schema definitions are separated into other crate, implementing Clone for ExistingType will happen compile error. cf. adwhit#93
Bumping this request, as I ran into this same limitation after a full day of trying to get Enums working in Diesel. My use case is a |
In addition to the patch by @yagince, could there be a |
I have separated schema.rs into different crates as workspace because it takes time for macro expansion of diesel.
If I define an enum in the workspace that references that crate and try to derive
DbEnum
to that enum, I get a compile error.diesel-derive-enum/src/lib.rs
Lines 389 to 393 in 36c44a2
Here, the reason was that diesel-derive-enum implements
Clone
for the type generated by diesel-cli.Currently, you can add
Clone
to the types generated by diesel-cli by addingClone
tocustom_derive_types
, so you can addClone
to the types generated by diesel-cli.I think the above code is no longer necessary.
What do you think?
The text was updated successfully, but these errors were encountered: