Closed rickyyx closed 6 years ago
Another thing if could be done, it will be awesome:
Generic Closure Use case:
let p = Piece::new(ArgsList, MyClosure);
p.run();
Potentially, a piece can hold on to any kind of function...but they need to belong to a certain trait object so that a common behaviour can be defined on them (aka, run()
).
This is resolved by erasing type information by converting T
to Any
, and some other indirections.
Fixed by ac62d9b13f89c4996025b7dceca32d891b1e6af2
Problem:
Currently, a generic transaction
Transaction<T>
can only support reads/writes of the same typeT
. However, in order for the transaction to allow multiple types at runtime, it cannot be tied with a single type (even generic type).Ideal Solution:
The best solution is to have generic associated types (GAT), which is still a rust feature being implemented. Tracking issue here: link
Current Solutions:
The current solution I can come up with is to use
Box<Any>
: Use ofAny
trait to have the users of the library to perform casting at runtime. This makes sense as the user (who defined the data) should know that type each read and write should be associated with. Such as below: