Description
The design of the context traits in src/traits.rs seems to mimic a C++-style inheritance based design by providing default implementations of trait functions, but this prevents certain code patterns from working because of the borrow checker, e.g. iterating mutably over a struct field while calling self.dispatch_http_call
and storing the returned token in the field. Because dispatch_http_call
takes my context struct as a &self
parameter, I can not call it while having a field of my struct mutably borrowed, as is the case when iterating mutably.
Note that none of these default implementations actually access the self
parameter, they all just call something from the hostcalls
module. It also seems like it doesn't make much sense to override most of them, except the ones that the host calls for us.
The proxy-sdk
crate seems to have found a design that meshes better with the way things work in Rust. (I am not affiliated with them and haven't tried it out yet.)