I'm pretty new to Rust, so there is the possibility that this will be an easy Question.
I'm trying to create a small registry for Handlers that should return any struct that implements the TransferObject
Trait:
pub trait TransferObject: Hash + PartialEq {}
Since I store the Handlers that are registered in a HashMap
the Trait needs the Hash
and PartialEq
as the Supertraits:
pub struct RequestHandlerRegistry {
handlers: HashMap<RequestMethod, HashMap<String, RequestHandler<dyn TransferObject>>>,
}
But in the Struct I get the Error, that TransferObject
can't be made into an Object since PartialEq
uses the parameter Self
.
I already tried to do something like this:
pub struct RequestHandlerRegistry {
handlers: HashMap<RequestMethod, HashMap<String, RequestHandler<Box<dyn TransferObject>>>>,
}
But I still get the same Error.
Is there some way to get around this?
I also created a Playground for easy recreation of the Error.