trait MacroInstances[Implicits, Instances] extends AnyRef

Intermediate factory that creates an Instances trait based on provided Implicits. Normally, this factory is used as implicit constructor parameter of base classes for companion objects of RPC traits (e.g. com.avsystem.commons.rest.DefaultRestApiCompanion) or ADTs (e.g. com.avsystem.commons.rest.RestDataCompanion). This all serves to reduce boilerplate associated with companion declarations and makes RPC trait or ADT definitions as concise as possible. It also lets the programmer easily inject additional implicits into macro-materialization of typeclasses aggregated by Instances trait.

Instances is a trait that aggregates multiple macro materialized typeclass instances. There is no fixed interface for Instances, its abstract methods are inspected by MacroInstances.materialize macro and implemented by inserting appropriate materializer macro invocation for each typeclass. By default it will be assumed that the typeclass has a macro named materialize in its companion object so each method will get <ResultTypeCompanion>.materialize as its implementation. This may be overridden with materializeWith annotation used on the method. This way you can specify both the object which contains the materializer macro and its name.

Additionally, all non-implicit parameters of each method in Instances trait will be automatically passed to the materializer macro. See HasGenCodecFromAU for an example of this mechanism.

Example of Instances: com.avsystem.commons.rest.ClientInstances

The Implicits type specifies additional implicits that will be automatically imported into macro materialization. Implicits is usually a singleton type of an object which contains these implicits. It may also be a tuple - contents of each tuple component will be imported independently. This way you can combine multiple sources of additional implicits. If you don't want to import any additional implicits, simply use Unit.

If MacroInstances is accepted as implicit super constructor parameter of a companion object (which is the typical situation) then this reference should be passed as companion. This is in order to work around https://github.com/scala/bug/issues/7666. Actual typeclass instances aggregated by Instances trait should be extracted into implicit lazy val definitions in the companion base class. See e.g. com.avsystem.commons.rest.RestDataCompanion for an example of how it's done.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. MacroInstances
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def apply(implicits: Implicits, companion: Any): Instances

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  10. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  12. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  14. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  15. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  16. def toString(): String
    Definition Classes
    AnyRef → Any
  17. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  18. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  19. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped