io.scalaland.chimney.protobufs.ProtobufsPartialTransformerImplicits.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of chimney-protobufs_2.13 Show documentation
Show all versions of chimney-protobufs_2.13 Show documentation
Integrations with selected Protobufs build-in types
The newest version!
package io.scalaland.chimney.protobufs
import io.scalaland.chimney.{partial, PartialTransformer}
/** @since 0.8.0 */
trait ProtobufsPartialTransformerImplicits extends ProtobufsPartialTransformerImplicitsLowPriorityImplicits1 {
/** @since 0.8.0 */
implicit def partialTransformerFromEmptyOneOfInstance[From <: scalapb.GeneratedOneof { type ValueType = Nothing }, To]
: PartialTransformer[From, To] =
PartialTransformer(_ => partial.Result.fromEmpty)
/** @since 1.3.0 */
implicit def partialTransformerFromEmptySealedOneOfInstance[From <: scalapb.GeneratedSealedOneof with Singleton, To]
: PartialTransformer[From, To] =
PartialTransformer(_ => partial.Result.fromEmpty)
/** @since 1.3.0 */
implicit def partialTransformerFromUnrecognizedEnumInstance[From <: scalapb.UnrecognizedEnum, To]
: PartialTransformer[From, To] =
PartialTransformer(_ => partial.Result.fromEmpty)
}
private[protobufs] trait ProtobufsPartialTransformerImplicitsLowPriorityImplicits1 {
this: ProtobufsPartialTransformerImplicits =>
// com.google.protobuf.empty.Empty
/** @since 0.8.0 */
implicit def partialTransformerFromEmptyInstance[A]: PartialTransformer[com.google.protobuf.empty.Empty, A] =
PartialTransformer(_ => partial.Result.fromEmpty)
// com.google.protobuf.duration.Duration
/** @since 0.8.0 */
implicit val partialTransformerFromScalaDurationToDurationInstance
: PartialTransformer[scala.concurrent.duration.Duration, com.google.protobuf.duration.Duration] =
PartialTransformer {
case _: scala.concurrent.duration.Duration.Infinite =>
partial.Result.fromErrorString(
"scala.concurrent.duration.Duration.Infinite cannot be encoded as com.google.protobuf.duration.Duration"
)
case duration: scala.concurrent.duration.FiniteDuration =>
partial.Result.fromValue(totalTransformerFromScalaFiniteDurationToDurationInstance.transform(duration))
}
}