swift, troubles with generic parameters and constraints

52 Views Asked by At

I'm writing some tests and mocks for my product but I'm having troubles with generic parameters and constraints...

enum ApiResult<Success, Failure> where Failure: Error {
    case success(Success)
    case failure(Failure)
    case disconnected
}

var askedDecodableApiResult: ApiResult<Decodable, Error> = .disconnected

func complete<T>(callback: @escaping (ApiResult<T, Error>) -> Void) where T: Decodable {
    callback(askedDecodableApiResult) //  Cannot convert value of type 'ApiResult<Decodable, Error>' to expected argument type 'ApiResult<T, Error>'
}

I'm lost with that error. What should I do to be able to send in my callback the pre-defined answer ? In the end, I want to be able to give my askedDecodableApiResult any ApiResult sporting a value that either inherits from Decodable or inherits from Error.

I need your help, thanks in advance :)

0

There are 0 best solutions below