Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete covariance from transformers #327

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/main/scala/io/moia/protos/teleproto/Reader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import scala.util.Try
/** Provides reading of a generated Protocol Buffers model into a business model.
*/
@implicitNotFound("No Protocol Buffers mapper from type ${P} to ${M} was found. Try to implement an implicit Reader for this type.")
trait Reader[-P, +M] {
trait Reader[P, M] {

/** Returns the read business model or an error message.
*/
Expand Down Expand Up @@ -150,6 +150,13 @@ object Reader extends LowPriorityReads {
PbSuccess((Duration(protobuf.seconds, SECONDS) + Duration(protobuf.nanos.toLong, NANOSECONDS)).toCoarsest)
}

/** Transforms a ScalaPB duration into a Scala concurrent duration.
*/
implicit object DurationReader extends Reader[PBDuration, Duration] {
def read(protobuf: PBDuration): PbResult[FiniteDuration] =
PbSuccess((Duration(protobuf.seconds, SECONDS) + Duration(protobuf.nanos.toLong, NANOSECONDS)).toCoarsest)
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copypasted from FiniteDurationReader because we need a separate reader now.


/** Transforms a string into a UUID.
*/
implicit object UUIDReader extends Reader[String, UUID] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ object VersionedModelWriter {
def writer: Writer[DetachedModel, SpecificModel]

final def versioned[V](version: V): (V, Writer[DetachedModel, GeneratedMessage]) =
version -> writer
version -> writer.map[GeneratedMessage](m => m)
}

object CompanionWriter {
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/io/moia/protos/teleproto/Writer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import scala.concurrent.duration.{Deadline, Duration}
@implicitNotFound(
"No mapper from business model type ${M} to Protocol Buffers type ${P} was found. Try to implement an implicit Writer for this type."
)
trait Writer[-M, +P] {
trait Writer[M, P] {

/** Returns the written Protocol Buffer object.
*/
Expand Down
8 changes: 7 additions & 1 deletion src/main/scala/io/moia/protos/teleproto/WriterImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ class WriterImpl(val c: blackbox.Context) extends FormatImpl {
// look for an implicit writer
val writerType = appliedType(c.weakTypeTag[Writer[_, _]].tpe, modelType, protobufType)

val existingWriter = c.inferImplicitValue(writerType)
val existingWriter =
try {
c.inferImplicitValue(writerType)
} catch {
// Return EmptyTree in case of errors
case _: Throwable => EmptyTree
}

// "ask" for the implicit writer or use the found one
def ask: Compiled = (compileInner(q"implicitly[$writerType]"), Compatibility.full)
Expand Down