-
-
Notifications
You must be signed in to change notification settings - Fork 283
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
Owned formats and representing formats as unit structs #546
Comments
From what it sounds like, you're trying to use it with serde. That doesn't require a struct at all, and can be accomplished using the This is unrelated to whether something is a struct, the struct's size, and constructing an |
Related to #350 only in that that issue is about making formatting a general-purpose crate, and I expect that to solve this issue as a side effect. |
Not at all. As I said, it is a strictly internal restructuring to avoid duplicating code. Even if the trait is made publicly implementable from a Setting that aside, I still don't see why something has to be a unit struct. The performance gain would be essentially zero without writing the entire parser/formatter by hand, as is done for the well-known formats. |
You're right, this is an X/Y problem. I don't want unit structs, I want to reuse formats. With well-known formats it's super easy, but custom formats generated with Which is not terrible, but there's no reason in principle why custom formats can't look the same as well-known formats and can't be declared at the type level as one-liners.
|
Maybe this should have been a discussion 😄 |
What leads you to believe this? You can assign the value to a const directly. I have been careful to ensure that the values output are compatible with doing this. There is even one place where this is required to make tests compile: link. Having
|
Oh, I never thought to try! Thank you 😄 |
It is currently nontrivial to construct a unit struct that represents a format similar to the well-known ones.
This is convenient when it makes sense to implement other features for individual formats.
For example,
impl MyFormat { pub fn deserialize() {} }
makes it convenient to deserialize fields with#[serde(deserialize_with = "MyFormat::deserialize")]
.One workaround that might work now is a
struct MyFormat(OwnedFormatItem)
withDeref
. But constructing anOwnedFormatItem
from a macro is also nontrivial.Ideally we would have a way to compose unit struct format representations somehow.
Related: #350
The text was updated successfully, but these errors were encountered: