-
Notifications
You must be signed in to change notification settings - Fork 125
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
Serde like rename
for Display trait on enum
#216
Comments
This sounds useful. It fits well with the FromStr for unit enum support that was introduced in #176. bikeshed: I think I prefer |
A good question raised in the thread in #225 would be what should be the default? My summary of that discussion is that there are two different usages for which a different default makes sense:
I'd say go for strict by default for now, i.e. error by default. Then if that is deemed too cumbersome we can always relax the default. However, unrelaxing the default would be a breaking change. |
Actually
I think that going explicitly over implicitly is a viable option, but only when it's consistent. We already have 2 examples for implicit display: #[derive(Display)]
struct Unit;
#[derive(Display)]
struct SingleField(u8); // works for named `{ field: u8 }` too I see implicit #[derive(Display)]
enum Enum {
A,
B,
} Moreover this behaviour is already usable on // derive_more::From fits nicely into this pattern as well
#[derive(Debug, Display, Error, From)]
enum CompoundError {
Simple,
WithSource {
source: Simple,
},
#[from(ignore)]
WithBacktraceFromSource {
#[error(backtrace)]
source: Simple,
},
#[display(fmt = "{source}")]
WithDifferentBacktrace {
source: Simple,
backtrace: Backtrace,
},
WithExplicitSource {
#[error(source)]
explicit_source: WithSource,
},
#[from(ignore)]
WithBacktraceFromExplicitSource {
#[error(backtrace, source)]
explicit_source: WithSource,
},
Tuple(WithExplicitSource),
WithoutSource(#[error(not(source))] Tuple),
} |
Any update on this issue? Applying a pre processing function on every variant name is very useful in different situations. |
Okay this dropped off my radar. @marcocondrache at the moment we're focussing on tasks that are blockers of 1.0.0, this is not one of them, because it can be implemented in a backwards compatible way. Feel free to contribute a PR that implements this. @ilslv Sorry I didn't respond. Your response make total sense. Let's go with |
`display(rename_all = "snake_case")` does not actually seem to be a thing, that is supported by `derive_more` [1]. Here, for sake of simplicity, i manually named the fields. Alternatively, we could change the "extra_headers" to `Map<String, serde_json::Value>`, which would then allow using the `Serialize` derive here as intended. [1]: <JelteF/derive_more#216>
`CatalogQoS` is represents the QoS classes exposed by macos and described for example in [1]. As of now we don't have a usecase for the majority of these, and will start with only using `background` for `upgrade`/`resolve` requests made by the `check_for_upgrade` command, which runs ... in the background. Additional classes are included to provide a "proven" framework for QoS classes in full. [1]: <https://blog.xoria.org/macos-tips-threading/> fix: provide display name for each class manually `display(rename_all = "snake_case")` does not actually seem to be a thing, that is supported by `derive_more` [1]. Here, for sake of simplicity, i manually named the fields. Alternatively, we could change the "extra_headers" to `Map<String, serde_json::Value>`, which would then allow using the `Serialize` derive here as intended. [1]: <JelteF/derive_more#216>
`CatalogQoS` is represents the QoS classes exposed by macos and described for example in [1]. As of now we don't have a usecase for the majority of these, and will start with only using `background` for `upgrade`/`resolve` requests made by the `check_for_upgrade` command, which runs ... in the background. Additional classes are included to provide a "proven" framework for QoS classes in full. [1]: <https://blog.xoria.org/macos-tips-threading/> fix: provide display name for each class manually `display(rename_all = "snake_case")` does not actually seem to be a thing, that is supported by `derive_more` [1]. Here, for sake of simplicity, i manually named the fields. Alternatively, we could change the "extra_headers" to `Map<String, serde_json::Value>`, which would then allow using the `Serialize` derive here as intended. [1]: <JelteF/derive_more#216>
`CatalogQoS` is represents the QoS classes exposed by macos and described for example in [1]. As of now we don't have a usecase for the majority of these, and will start with only using `background` for `upgrade`/`resolve` requests made by the `check_for_upgrade` command, which runs ... in the background. Additional classes are included to provide a "proven" framework for QoS classes in full. [1]: <https://blog.xoria.org/macos-tips-threading/> fix: provide display name for each class manually `display(rename_all = "snake_case")` does not actually seem to be a thing, that is supported by `derive_more` [1]. Here, for sake of simplicity, i manually named the fields. Alternatively, we could change the "extra_headers" to `Map<String, serde_json::Value>`, which would then allow using the `Serialize` derive here as intended. [1]: <JelteF/derive_more#216>
Also should this only be available for |
Took a shot at implementing this in #443, still have to write documentation. |
i.e. I would expect
The serde behaviour is documented here:
https://serde.rs/container-attrs.html#rename_all
The text was updated successfully, but these errors were encountered: