I prefer this to an attribute. Also, even with this approach, users can combine multiple namespaces, by creating protocols for each one and then sharing them.
E.g.
protocol HTMLDiv {}
extension HTMLDiv {
static func div(@HTMLBuilder _ builder: () -> HTMLValue) -> HTMLValue { … }
}
protocol HTMLHeaders {}
extension HTMLHeaders {
static func h1(_ text: String) -> HTMLValue { … }
// h2, h3, etc.
}
@resultBuilder enum CustomHTMLBuilder {
enum Namespace: HTMLDiv, HTMLHeaders {}
}
This reminds me of the SwiftPredicates pitch, where one of the main reasons for using macros is that operator overloading is too slow. Maybe with scoped unqualified lookup, the macro could be replaced with standard, well understood features for adding custom operators.
How will users opt out of name lookup in the result-builder namespace? Also would a type in the namespace be prioritized over a module name, e.g. ThisModule.div or Swift.OneOrMore?