PoignardAzur / venial

"A very small syn"
MIT License
196 stars 7 forks source link

Some API design criticisms #20

Closed rodrimati1992 closed 2 years ago

rodrimati1992 commented 2 years ago

Here I'll give some criticisms (and alternate designs) of the API, repeating some I've just given in the community server macros channel.

I've found TyExpr's name confusing, because I expected it to be an expression, but it's actually just a type. It's conflating two syntactically distinct things in its name.

In Attributes, tk_braces is not a pair of { and }, which is what proc_macro and syn call Brace. To be consistent with both it'd have to be tk_bracket.

In Attributes, tk_equals, tk_group, tk_value would be better modeled as an Argument, where Argument is these variants:

Argument would also have methods for getting the tk_* fields that were rewritten into it.

This design for Attributes removes mismatched Option fields (ie: tk_equals is Some, but tk_value is None), so users don't have to return errors (or panic) when they're mismatched anymore.

PoignardAzur commented 2 years ago

Type expressions are a valid Rust construct. But maybe I'll change the name.

Otherwise, your criticisms make sense.