CastBackendMacro.swift 1010 B

123456789101112131415161718192021
  1. /// Modifies a function body in a view implementation to automatically
  2. /// cast a backend instance.
  3. ///
  4. /// This is for internal SCUI use and should not be exposed publicly -- the
  5. /// macro is not especially robust and only performs minimal checking.
  6. ///
  7. /// This macro expects to be attached to a `func` declaration with a parameter
  8. /// named `backend`. It will also recognize a parameter named `widget` and will
  9. /// insert the appropriate cast.
  10. ///
  11. /// - Parameters:
  12. /// - backendGenericName: The name of the generic parameter to the inner
  13. /// function. If `nil`, one will be generated randomly.
  14. /// - returnsWidget: Whether the attached function returns a widget. If it
  15. /// does, the macro will insert an extra cast to make sure the correct
  16. /// widget type comes out.
  17. // @attached(body)
  18. // internal macro CastBackend<NewBackend>(
  19. // backendGenericName: String? = nil,
  20. // returnsWidget: Bool = false
  21. // ) = #externalMacro(module: "SwiftCrossUIMacrosPlugin", type: "CastBackendMacro")