Protocol as a type cannot conform to the protocol itself

filip-sakel shared this in AnyCodable Efficacy. To paraphrase: the existential box is opened on protocol methods, so by extending/trampolining off the protocol we can get access to the real type again. Genius!

Here's a worked example.

protocol Stuffable { }
struct Stuffer: Stuffable { }

func withStuff<T>(_ stuff: T) where T: Stuffable {
    print("Hello \(T.self)")
}

extension Stuffable {
    func trampoline() { withStuff(self) }
}

let value: Stuffable = Stuffer()
withStuff(value)      ❌
value.trampoline()    ✅
5 Likes