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
Currently, FromMeta has a number of different optional methods, which correspond to different values that might be encountered when parsing. With the release of syn 2.0, does it make sense to streamline the trait down to only three methods:
traitFromMeta{fnfrom_meta(meta:&Meta) -> Result<Self>;/// We'd still recommend not inspecting the value of `path` here, but passing it through/// gives the implementer access to the span and the value for generating diagnostics.fnfrom_path(path:&Path) -> Result<Self>;/// Not sure what type this should take; the current slice has its problems, but I do/// like that the slice provides a way to filter out or inject list items into the collectionfnfrom_list(??) -> Result<Self>;fnfrom_expr(expr:&Expr) -> Result<Self>;/// This will continue to be used to fill in optional fields.fnfrom_none() -> Option<Self>;}
darling could provide utility functions or Ext traits to make custom impls of from_expr easier; their exact design would need further investigation.
Advantages
Consolidating these methods would make FromMeta much simpler: Each variant of syn::Meta would correspond to one of the overridable functions, with a total takeover being possible-but-not-recommended using from_meta
This consolidation also ensures that each function has access to the best available span information, which is important for building good diagnostic messages.
Disadvantages
I don't know how many users of the crate this would break.
Without good helpers, writing a custom FromMeta that wants to do something simple (like parse a string) will become more verbose, and the barrier to customization will go up. It should be dead-simple to write a custom impl for a newtype struct that wraps an IpV4Addr, for example.
Are you custom-implementing FromMeta
No
100%
Yes, but I DO NOT write custom implementations of from_bool, from_word, from_string, from_value, or from_char
0%
Yes, and I DO write custom implementations of from_bool, from_word, from_string, from_value, or from_char
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Currently,
FromMeta
has a number of different optional methods, which correspond to different values that might be encountered when parsing. With the release of syn 2.0, does it make sense to streamline the trait down to only three methods:darling
could provide utility functions orExt
traits to make custom impls offrom_expr
easier; their exact design would need further investigation.Advantages
Consolidating these methods would make
FromMeta
much simpler: Each variant ofsyn::Meta
would correspond to one of the overridable functions, with a total takeover being possible-but-not-recommended usingfrom_meta
This consolidation also ensures that each function has access to the best available span information, which is important for building good diagnostic messages.
Disadvantages
FromMeta
that wants to do something simple (like parse a string) will become more verbose, and the barrier to customization will go up. It should be dead-simple to write a custom impl for a newtype struct that wraps anIpV4Addr
, for example.1 vote ·
Beta Was this translation helpful? Give feedback.
All reactions