No it's a library, but you can't use it with @dynamicMemberLookup, I didn't realize that was the question. I don't think there's any current way to forward enum cases with dynamic member lookup without using some hacky workaround.
public enum CodingKeys: String {
case id = "_id"
case address = "a"
public struct Namespace {
var id: CodingKeys { .id }
var address: CodingKeys { .address }
}
}
extension SomeDatabase.SomeModel {
static subscript(dynamicMember member: KeyPath<CodingKeys.Namespace, CodingKeys>) -> String {
CodingKeys.Namespace()[keyPath: member].rawValue
}
}
like i said, SwiftUI-style result builders are unkeyed, so they’re not really great for the kind of “key-value shaped” things like BSON. this is where subscript assignment really shines in my opinion.
I thought static keypaths weren’t supported at all. I’m surprised the error is what it is, but iirc I tried to get around that with a static protocol extension once and got a much more clear error message.