Calling a specific method on a struct that implements a generic trait

I've got a trait IDriven<T> which defines a method create(&self, entity: T). I've implemented this trait for multiple types on the struct Respository - now I wish to call create for a specific type on an instance of Repository - but I can't figure out how to properly call it?

I've got this:

impl IService for ScriptCreateSvc {
    type Input = Script;
    type Output = Script;
    type Entity = Script;

    fn execute(respository: &impl IDriven<Script>, script: Script) -> Result<Script, DomainError> {
        // This works, but if I include more implementation bounds in the function signature i need to call a specific impl.
        let s1 = respository.create(script)?;
        // I've been trying to call a specific implementation of IDriven<T> like this, but it complains the trait is not satisfied, see below
        let s2 = IDriven::<Script>::create(&respository, script);

In my second attempt s2 above I get this compiler error:

the trait IDriven<entities::tag::Tag> is not implemented for &impl IDriven<Strategy>

How can IDriven<Tag> not be implemented for an anonymous type that implements that trait for that concrete type..?

I ended up doing this, it seems to do the job:

impl IService for StrategyCreateSvc {
    type Input = Strategy;
    type Output = Strategy;

    fn execute<Repository>(
        repository: &Repository,
        strategy: Strategy,
    ) -> Result<Strategy, DomainError>
        Repository: IDriven<Tag>,
        Repository: IDriven<Script>,
        let s = IDriven::<Tag>::get_by_id(repository, 1);

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.