Closed ohitsdaniel closed 3 years ago
As the avoiding erasing to AnyView lead to PathBuilder being a generic struct, we would have to define the for returns which can be tedious.
Instead, we'll leverage opaque result types and use the some keyword in factory functions returning PathBuilders.
some
Had to introduce the PathBuilders namespace enum, as static members cannot be used on protocol metatypes. :(
Check out this example regarding this issue 🔝
protocol Builder { associatedtype Content func build() -> Content } struct B<Content>: Builder { let _build: () -> Content func build() -> Content { _build() } } extension Builder { static func builder() -> some Builder { B(_build: {1}) } } let f = { Builder.builder() }
Comes with the drawback, that we now have to type PathBuilders.screen etc. whenever we want to instantiate a particular path builder, but that's better than erasing to AnyView.
As the avoiding erasing to AnyView lead to PathBuilder being a generic struct, we would have to define the for returns which can be tedious.
Instead, we'll leverage opaque result types and use the
some
keyword in factory functions returning PathBuilders.Had to introduce the PathBuilders namespace enum, as static members cannot be used on protocol metatypes. :(
Check out this example regarding this issue 🔝
Comes with the drawback, that we now have to type PathBuilders.screen etc. whenever we want to instantiate a particular path builder, but that's better than erasing to AnyView.