7 releases
0.1.6 | May 26, 2022 |
---|---|
0.1.5 | May 26, 2022 |
#238 in Algorithms
3,131 downloads per month
1MB
25K
SLoC
Module :: fundamental_data_type
Fundamental data types and type constructors, like Single, Pair, Homopair, Many.
In Rust, you often need to wrap a given type into a new one. The role of the orphan rules in particular is basically to prevent you from implementing external traits for external types. To overcome the restriction developer usually wrap the external type into a tuple introducing a new type. Type constructor does exactly that and auto-implement traits From, Into, Deref and few more for the constructed type.
Besides type constructor for single element there are type constructors for pair
, homopair
and many
:
Single
to wrap single element.Pair
to wrap pair of distinct elements.HomoPair
to wrap pair of elements with the same type.Many
to wrapVec
of elements.
To add to your project
cargo add type_constructor
Try out from the repository
git clone https://github.com/Wandalen/wTools
cd wTools
cd sample/rust/type_constructor_trivial_sample
cargo run