You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using the Decimal type from the rust_decimal crate. It doesn't have a AsTypeDescription impl. In order to use it with my types (using the TypeDescription derive macro), I have to wrap it in a new type that I manually implement AsTypeDescription for.
What I'd love to do instead is just write a function that provides a TypeDescription, and then annotate the field with the name of that method.
So, currently:
implDerefforDecimal{typeTarget = rust_decimal::Decimal;fnderef(&self) -> &Self::Target{&self.0}}implAsTypeDescriptionforDecimal{fnas_type_description() -> TypeDescription{TypeDescription::new("Decimal".to_string(),TypeKind::Float{size:128},Some("A decimal type used to precisely store floats"))}}#[derive(Copy,Clone,PartialEq,Eq,Deserialize,Serialize,TypeDescription)]#[serde(rename_all = "camelCase")]pubstructImageProperties{pubinches_w:Decimal,pubinches_h:Decimal,// Other fields that it can auto-derive}
But what I'd like is to have this:
fndecimal_type_description() -> TypeDescription{TypeDescription::new("Decimal".to_string(),TypeKind::Float{size:128},Some("A decimal type used to precisely store floats"))}#[derive(Copy,Clone,PartialEq,Eq,Deserialize,Serialize,TypeDescription)]#[serde(rename_all = "camelCase")]pubstructImageProperties{#[description(provider = decimal_type_description)]pubinches_w: rust_decimal::Decimal,#[description(provider = decimal_type_description)]pubinches_h: rust_decimal::Decimal,// Other fields that it can auto-derive}
Alternatives
Has the feature been requested before?
If the feature request is approved, would you be willing to submit a PR?
I think so, though I'd need help submitting a PR.
The text was updated successfully, but these errors were encountered:
It describes the individual fields used. You should be able to then check the call sites, and for example add a check to the following iterator where you look for the new attribute.
You should be able to check if you cover all cases by making tests for all situations where it could be used:
On struct fields
On a tuple struct field
On enum struct fields
On enum tuple fields
Some negative tests are also great (check out the compile fail examples), mainly making sure the function actually gets typechecked + the output should be somewhat sane.
Context
I'm using the Decimal type from the rust_decimal crate. It doesn't have a AsTypeDescription impl. In order to use it with my types (using the TypeDescription derive macro), I have to wrap it in a new type that I manually implement AsTypeDescription for.
What I'd love to do instead is just write a function that provides a TypeDescription, and then annotate the field with the name of that method.
So, currently:
But what I'd like is to have this:
Alternatives
Has the feature been requested before?
If the feature request is approved, would you be willing to submit a PR?
I think so, though I'd need help submitting a PR.
The text was updated successfully, but these errors were encountered: