How to create a enum-like struct macro?

it needs to be an extension macro, because it requires a conformance to RawRepresentableByIntegerEncoding to be present, otherwise there is no way of knowing if init(rawValue:) is available.

public
protocol RawRepresentableByIntegerEncoding<RawValue>:RawRepresentable
    where RawValue:ExpressibleByIntegerLiteral
{
    init(rawValue:RawValue)
}

@attached(extension, names: arbitrary, conformances: RawRepresentableByIntegerEncoding)
public
macro RawRepresentableByIntegerEncoding(_ strings:String...) = #externalMacro(
    module: "InlineValueMacros",
    type: "InlineASCII.ConstructorMacro")

1 Like