Skip to content
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

Consider making "built-in" complex types more strongly typed #131

Open
ascjones opened this issue Sep 1, 2021 · 2 comments
Open

Consider making "built-in" complex types more strongly typed #131

ascjones opened this issue Sep 1, 2021 · 2 comments
Labels
Milestone

Comments

@ascjones
Copy link
Contributor

ascjones commented Sep 1, 2021

Currently builtin types like Option, Result, Range etc. are defined as normal Composite or Variant types in the prelude. One downside to this is that it requires string matching in downstream consumers in order to identify the types.

One option to make it more strongly typed would be to introduce another top level variant e.g. BuiltIn or Prelude which contains a sub enum which would cover all the possible prelude types.

This would make it easier to differentiate between user defined types and built-in scale-info types.

Related #130

@ascjones ascjones added the idea label Sep 1, 2021
@Robbepop
Copy link
Contributor

Robbepop commented Sep 1, 2021

We could make the path representable as builtin which is only allowed from within the scale-info crate. So user defined types cannot have a builtin path. The set of types with a builtin path must be fixed and known upfront - e.g. Option<T>, Result<T, E>, Range, ... This way we avoid another huge set of ever growing enum variants for every builtin type but third party tools have a simple and efficient way of detecting an actually builtin type and differentiating one from a user defined type.
This kinda is possible nowadays with the prelude path if we were able to stop users from defining types with such a path.

Instead of making path more complex by introducing a builtin path we could also simply use a bool flag is_builtin that defaults to false and is not serialized therefore for all non-builtin types.

@ascjones ascjones added this to the 2.0 milestone Sep 1, 2021
@ascjones
Copy link
Contributor Author

ascjones commented Sep 1, 2021

At the moment all those types are in the "prelude" namespace (i.e. no namespace in the path), but there is nothing at the moment to stop a custom type being constructed with an empty namespace.

Anyway I have already released 1.0 now so added this to the 2.0 milestone. It's not a showstopper but we can certainly improve the experience here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants