[Feature] change `EvmFactory` trait to let implementers use a stricter trait for the generic `DB` to give to the EVM
alessandromazza98 opened this issue · comments
Describe the feature you would like
Right now the EvmFactory
trait in the alloy-evm
crate has an associated type called Evm
that has a generic DB: alloy_evm::Database
.
Line 197 in 224bf74
This makes it impossible in the concrete implementation to use a trait that is stricter than the alloy_evm::Database
trait because of how Rust compiler works with generic defined on associated types (instead of the generic being defined in the trait itself - something like pub trait EvmFactory<DB: Database>
.
Do you think it could make sense to change the trait such that it lets implementers use a stricter (meaning it's at least Database
, but it may have additional requirements such as thread safety Send + Sync
or clonable Clone
) trait on the DB.
I'm down to help here if you give me some guidance and find the proposal appealing.
Additional context
No response
pub trait EvmFactory<DB: Database>
this doesn't really work for how we intend to use it because this then requires slapping a generic all over the pace
have you tried restricting you impl like this
Lines 140 to 142 in 224bf74
maybe this could work for your use case?
maybe this could work for your use case?
thanks for the answer. As of now I'm trying to use a different strategy to overcome this issue - i.e. trying to make the DB
implements alloy_evm::Database
and move the stricter traits in different places.
I don't think what you suggest can be applied in the EvmFactory
trait, specifically for the DB
generic on the Evm
associated type