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 automatically as <methodReturnTypeCompanion>.materialize
Therefore, return type type of each method must have a companion object which contains materialize macro.
You can customize this by applying MacroInstances.materializeWith annotation on methods of Instances trait.
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.
Intermediate factory that creates an
Instances
trait based on providedImplicits
. 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 byInstances
trait.Instances
is a trait that aggregates multiple macro materialized typeclass instances. There is no fixed interface forInstances
, its abstract methods are inspected byMacroInstances.materialize
macro and implemented automatically as<methodReturnTypeCompanion>.materialize
Therefore, return type type of each method must have a companion object which containsmaterialize
macro. You can customize this by applying MacroInstances.materializeWith annotation on methods ofInstances
trait.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 useUnit
.If
MacroInstances
is accepted as implicit super constructor parameter of a companion object (which is the typical situation) thenthis
reference should be passed ascompanion
. This is in order to work around https://github.com/scala/bug/issues/7666. Actual typeclass instances aggregated byInstances
trait should be extracted intoimplicit lazy val
definitions in the companion base class. See e.g.com.avsystem.commons.rest.RestDataCompanion
for an example of how it's done.