Hi,
I'm implementinga simple web api with rust to get away from the Spring world.
Background Info why I'm asking this specifically but might not be actually relevant to the answer.
I do want to use mutiple layers within the api like:
HTTP -> ApplicationService -> BusinessService -> Persistence
In the Spring world I would create multiple such services and auto inject the dependencies at startup.
I figured I could do without such service instances in rust by just using public methods decoupled by modules:
mod Persistence {}
mod Business {
//call persistence
}
mod Application {
// call business
}
That way I would loose a way to unit test these modules alone.
Because of that I thought I would create Traits for each of these modules which could be mocked. <- that works fine with a few adjustments
Let's say I have a Trait
pub trait Persistence {
// definitions
}
and a struct that has a member of a impl of the Persistence Trait i figured two ways of doing this:
pub struct Service<Pers: Persistence + Sync + Send + OtherTraits> {
repo: Pers
}
pub struct Service {
repo: dyn Persistence + Sync + Send + OtherTraits
}
which one would be the better fit? I would have to put the generic on every impl I do for the struct which is quite verbose to me.