Open pierresouchay opened 4 years ago
Unfortunately the keyword type doesn't introduce a new type, only a type alias. So while this will make code more readable it can lead to some surprises and won't introduce strong types. A good article on this can be found here: https://doc.rust-lang.org/1.8.0/book/type-aliases.html
I wrote a quick example of how you can have data easily move between these type aliases without the compiler stopping you: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=030d70ba1b7660bb76845ce43251d2ee
To get the strong typing we will need to implement each type as a new struct and provide the appropriate guidance to serde.
@stusmall In the current implementation, I did implement the following real types:
For now, 1, 2 and 3 seem Ok to me as it allows to enforce common semantics.
There are also those aliases:
I was wondering if moving slowly for no types to aliases and eventually real types do make sense or if we want directly to use strong types everywhere.
Can you tell me which types you don't want to be aliases?
@stusmall Do you have comments regarding https://github.com/stusmall/consul-rust/pull/39#issuecomment-603084048 ?
Will allow validating various datastructures (ex: serviceName with '/', Metadata limite keys/size...)