diff --git a/MIGRATION.md b/MIGRATION.md index b99395701..9af96e39b 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -54,6 +54,31 @@ the bottom of this file. Restoration ships incrementally per feature area. compiles). - `enum` was renamed to `e` at one call site in `GenKeyCodec` (`enum` is reserved in Scala 3). - `@targetName` annotation added to `CloseableIterator` overloaded methods. +- `implicit val/def` typeclass instances rewritten to `given` across `serialization`, `cbor`, + `meta`, `misc`, `tuples` (slice 3.3). Named-import callers that referenced these by name + (e.g. `GenCodec.bseqCodec`, `GenKeyCodec.IntKeyCodec`, `TypeString.codec`) must switch to + `summon[GenCodec[BSeq[T]]]` or use `import X.given` for given-import semantics. Anonymous + `given T = …` preferred for canonical instances per fork pattern. +- Named-import compatibility shims: `@deprecated def NAME: T = summon[T]` aliases added in + `BoxingUnboxing` (`BooleanBoxing` … `DoubleBoxing`, `BooleanUnboxing` … `DoubleUnboxing`) + and `GenKeyCodec` (`BooleanKeyCodec` … `BytesKeyCodec`) so downstream callers using + `GenKeyCodec.IntKeyCodec`-style named lookup keep compiling. Each shim emits a deprecation + warning pointing to `summon[T]`. Mirrors `BsonGenCodecs` source-compat layer from fork + commit `8f70be80`. +- `OptArg.argToOptArg` PRESERVED as `implicit def` — polymorphic `Conversion[A, OptArg[A]]` + would generate a clashing JVM erasure bridge (both `A` and the `OptArg` value class erase to + `Object`). Verbatim explanatory comment from fork `39c047eb` retained inline. +- `GenRef.fun2GenRef` PRESERVED as `implicit def` (currently a `???` Phase-2 stub; Phase 4 + feature-port will restore the macro-splice body; macro-splice-over-inline-arg rationale per + fork `ebffde26` documented as preservation rule). +- `RunNowEC.Implicits.executionContext` / `RunInQueueEC.Implicits.executionContext` PRESERVED + as `implicit val` — the wildcard-import-into-`Implicits`-object idiom is the public API + (`import RunNowEC.Implicits._`). Converting to `given` would silently stop providing the EC + to wildcard-import callers (givens require `import X.given`). +- `(implicit X: T)` parameter lists left in place across slice-3.1 extension-shim sites + (`SharedExtensions.implicit def *Ops`, jiop, jsiop, `Components.autoComponent`, etc.). Those + are conversion shims for `implicit class` value-class wrappers and are being rewritten to + `extension` blocks in slice 3.1 (PR #868), which deletes the conversion entirely. ### mongo @@ -63,10 +88,33 @@ the bottom of this file. Restoration ships incrementally per feature area. Scala 3 forbids type projections on non-concrete prefixes). Public-API signature change. - `BsonValueOutput.write` / `BsonValueInput.read` call sites require explicit `using` keyword. - `MongoPolyDataCompanion` / `TypedMapFormat` / `TypedMapRefOps` widened from `K[_]` / `D[_]` to `K[Any]` / `D[Any]`. +- `(implicit X: T)` parameter lists rewritten to `(using X: T)` across 19 mongo files in + slice 3.3 (BsonCodec, BsonRef, DocKey, Filter, GenCodecProvider, BsonRefIterable*, Sorting, + MongoOps, TextSearchLanguage, DataTypeDsl, MongoEntityCompanion, MongoIndex, + MongoPolyDataCompanion, MongoRef, MongoUpdateOperator, ProjectionZippers, QueryOperatorsDsl, + TypedMongoCollection). Source-compat: positional call sites unchanged (Scala 3 accepts both + syntaxes); named-arg call sites must update from `foo(x = …)` to `foo(using x = …)`. +- `BsonGenCodecs` rewritten per fork `8f70be80`: trait uses `export BsonGenCodecs.given`, + object holds anonymous `given GenCodec[X] = …` declarations + `@deprecated def name: T = summon` + shims for source-compat with named-import callers (`BsonGenCodecs.objectIdCodec`, etc.). +- `MongoFormat.codec` / `MongoAdtFormat.codec`/`dataClassTag` are now `given` in trait + declarations; consumers using `import meta.format._` to bring `codec`/`dataClassTag` into + implicit scope must switch to `import meta.format.{given, _}` for given-import semantics + (already applied internally in `TypedMongoCollection.mkNativeCollection`). +- `KeyGetter.bsonRefKeyGetter` / `docKeyKeyGetter` rewritten from `implicit object … extends T` + to `given X: T with { … }`. Source-compat: positional resolution unchanged; `import X._` + callers must switch to `import X.given`. ### hocon - `SealedEnumCompanion.values` override now `lazy val` (see core notes). +- `HoconGenCodecs` codec instances (`ConfigCodec`, `FiniteDurationCodec`, `JavaDurationCodec`, + `PeriodCodec`, `SizeInBytesCodec`, `ClassKeyCodec`, `ClassCodec`) rewritten from + `implicit final val` to `given` (slice 3.3). Same named-import caveat as the core entry + applies. +- `ConfigObjectCompanion.codec` instance and `DefaultConfigCompanion` macro-instance + parameter rewritten to `using`. +- `HTree.HIncludeQualifier` / `HStringSyntax` constructor implicit param rewritten to `using`. ## 4. Binary-compat breaks diff --git a/benchmark/jvm/src/main/scala/com/avsystem/commons/ser/GenCodecBenchmarks.scala b/benchmark/jvm/src/main/scala/com/avsystem/commons/ser/GenCodecBenchmarks.scala index 9d4fbad3e..da06eecbf 100644 --- a/benchmark/jvm/src/main/scala/com/avsystem/commons/ser/GenCodecBenchmarks.scala +++ b/benchmark/jvm/src/main/scala/com/avsystem/commons/ser/GenCodecBenchmarks.scala @@ -18,13 +18,13 @@ class GenCodecBenchmarks { @Benchmark def cleanSomeWriting: String = { - implicit val cleanCodec: GenCodec[Option[String]] = GenCodecBenchmarks.cleanOptionCodec[String] + given cleanCodec: GenCodec[Option[String]] = GenCodecBenchmarks.cleanOptionCodec[String] JsonStringOutput.write(GenCodecBenchmarks.somes) } @Benchmark def cleanNoneWriting: String = { - implicit val cleanCodec: GenCodec[Option[String]] = GenCodecBenchmarks.cleanOptionCodec[String] + given cleanCodec: GenCodec[Option[String]] = GenCodecBenchmarks.cleanOptionCodec[String] JsonStringOutput.write(GenCodecBenchmarks.nones) } @@ -34,7 +34,7 @@ class GenCodecBenchmarks { } object GenCodecBenchmarks { - implicit def cleanOptionCodec[T: GenCodec]: GenCodec[Option[T]] = + given cleanOptionCodec[T: GenCodec]: GenCodec[Option[T]] = GenCodec.create[Option[T]]( i => if (i.readNull()) None else Some(GenCodec.read[T](i)), (o, vo) => diff --git a/benchmark/jvm/src/main/scala/com/avsystem/commons/ser/StreamInputOutputBenchmark.scala b/benchmark/jvm/src/main/scala/com/avsystem/commons/ser/StreamInputOutputBenchmark.scala index 0c9aff3bd..b3419e7b6 100644 --- a/benchmark/jvm/src/main/scala/com/avsystem/commons/ser/StreamInputOutputBenchmark.scala +++ b/benchmark/jvm/src/main/scala/com/avsystem/commons/ser/StreamInputOutputBenchmark.scala @@ -11,8 +11,8 @@ case class Toplevel(int: Int, nested: Nested, str: String) case class Nested(list: List[Int], int: Int) object Toplevel { - implicit val nestedCodec: GenCodec[Nested] = GenCodec.materialize[Nested] - implicit val codec: GenCodec[Toplevel] = GenCodec.materialize[Toplevel] + given nestedCodec: GenCodec[Nested] = GenCodec.materialize[Nested] + given codec: GenCodec[Toplevel] = GenCodec.materialize[Toplevel] } @Warmup(iterations = 10) diff --git a/core/js/src/main/scala/com/avsystem/commons/serialization/nativejs/NativeFormatOptions.scala b/core/js/src/main/scala/com/avsystem/commons/serialization/nativejs/NativeFormatOptions.scala index b16cf1c65..f43e5feb3 100644 --- a/core/js/src/main/scala/com/avsystem/commons/serialization/nativejs/NativeFormatOptions.scala +++ b/core/js/src/main/scala/com/avsystem/commons/serialization/nativejs/NativeFormatOptions.scala @@ -6,7 +6,7 @@ import com.avsystem.commons.misc.{AbstractValueEnum, AbstractValueEnumCompanion, /** Specifies format used by `NativeJsonOutput.writeLong` / `NativeJsonInput.readLong` to represent [[Long]]. JS does * not support 64-bit representation. */ -final class NativeLongFormat(implicit ctx: EnumCtx) extends AbstractValueEnum +final class NativeLongFormat(using ctx: EnumCtx) extends AbstractValueEnum object NativeLongFormat extends AbstractValueEnumCompanion[NativeLongFormat] { final val RawString: Value = new NativeLongFormat final val JsNumber: Value = new NativeLongFormat @@ -16,7 +16,7 @@ object NativeLongFormat extends AbstractValueEnumCompanion[NativeLongFormat] { /** Specifies format used by `NativeJsonOutput.writeTimestamp` / `NativeJsonInput.readTimestamp` to represent * timestamps. */ -final class NativeDateFormat(implicit ctx: EnumCtx) extends AbstractValueEnum +final class NativeDateFormat(using ctx: EnumCtx) extends AbstractValueEnum object NativeDateFormat extends AbstractValueEnumCompanion[NativeDateFormat] { final val RawString: Value = new NativeDateFormat final val JsNumber: Value = new NativeDateFormat @@ -27,7 +27,7 @@ object NativeDateFormat extends AbstractValueEnumCompanion[NativeDateFormat] { * * Note that [[scala.scalajs.js.JSON.stringify]] does not know how to serialize a BigInt and throws an error */ -final class NativeBigIntFormat(implicit ctx: EnumCtx) extends AbstractValueEnum +final class NativeBigIntFormat(using ctx: EnumCtx) extends AbstractValueEnum object NativeBigIntFormat extends AbstractValueEnumCompanion[NativeBigIntFormat] { final val RawString: Value = new NativeBigIntFormat final val JsBigInt: Value = new NativeBigIntFormat diff --git a/core/jvm/src/main/scala/com/avsystem/commons/concurrent/BlockingUtils.scala b/core/jvm/src/main/scala/com/avsystem/commons/concurrent/BlockingUtils.scala index 985aa1408..191853846 100644 --- a/core/jvm/src/main/scala/com/avsystem/commons/concurrent/BlockingUtils.scala +++ b/core/jvm/src/main/scala/com/avsystem/commons/concurrent/BlockingUtils.scala @@ -15,7 +15,7 @@ abstract class BlockingUtils { /** Default scheduler used to run `Task`s and `Observable`s. This scheduler is not meant for blocking code. */ - implicit def scheduler: Scheduler + given scheduler: Scheduler /** Scheduler used for running blocking code. */ @@ -71,6 +71,6 @@ abstract class BlockingUtils { } object DefaultBlocking extends BlockingUtils { - implicit def scheduler: Scheduler = Scheduler.global + given scheduler: Scheduler = Scheduler.global lazy val ioScheduler: Scheduler = Scheduler.io() } diff --git a/core/jvm/src/main/scala/com/avsystem/commons/concurrent/ObservableBlockingIterator.scala b/core/jvm/src/main/scala/com/avsystem/commons/concurrent/ObservableBlockingIterator.scala index 7ae37a2b4..e29fd711d 100644 --- a/core/jvm/src/main/scala/com/avsystem/commons/concurrent/ObservableBlockingIterator.scala +++ b/core/jvm/src/main/scala/com/avsystem/commons/concurrent/ObservableBlockingIterator.scala @@ -19,7 +19,7 @@ class ObservableBlockingIterator[T]( timeout: Long, unit: TimeUnit, bufferSize: Int, -)(implicit val scheduler: Scheduler +)(using val scheduler: Scheduler ) extends CloseableIterator[T] with Subscriber[T] { diff --git a/core/src/main/scala/com/avsystem/commons/concurrent/executionContexts.scala b/core/src/main/scala/com/avsystem/commons/concurrent/executionContexts.scala index e694434f5..7a8b6d670 100644 --- a/core/src/main/scala/com/avsystem/commons/concurrent/executionContexts.scala +++ b/core/src/main/scala/com/avsystem/commons/concurrent/executionContexts.scala @@ -67,13 +67,13 @@ class RunInQueueEC extends ExecutionContextExecutor { } trait HasExecutionContext { - protected implicit def executionContext: ExecutionContext + protected given executionContext: ExecutionContext } trait HasRunNowEC extends HasExecutionContext { - protected implicit final def executionContext: ExecutionContext = RunNowEC + protected implicit val executionContext: ExecutionContext = RunNowEC } trait HasRunInQueueEC extends HasExecutionContext { - protected implicit final def executionContext: ExecutionContext = RunInQueueEC + protected implicit val executionContext: ExecutionContext = RunInQueueEC } diff --git a/core/src/main/scala/com/avsystem/commons/di/Component.scala b/core/src/main/scala/com/avsystem/commons/di/Component.scala index 0551161ea..d80bc8ae7 100644 --- a/core/src/main/scala/com/avsystem/commons/di/Component.scala +++ b/core/src/main/scala/com/avsystem/commons/di/Component.scala @@ -34,7 +34,7 @@ object ComponentInfo { ) @compileTimeOnly("implicit ComponentInfo is only available inside code passed to component/singleton macro") - implicit def info: ComponentInfo = sys.error("stub") + given info: ComponentInfo = sys.error("stub") } /** Represents a lazily initialized component in a dependency injection setting. The name "component" indicates that the diff --git a/core/src/main/scala/com/avsystem/commons/di/Components.scala b/core/src/main/scala/com/avsystem/commons/di/Components.scala index d635108b9..2c12698a1 100644 --- a/core/src/main/scala/com/avsystem/commons/di/Components.scala +++ b/core/src/main/scala/com/avsystem/commons/di/Components.scala @@ -43,11 +43,12 @@ trait Components extends ComponentsLowPrio { // avoids divergent implicit expansion involving `inject` // this is not strictly necessary but makes compiler error messages nicer // i.e. the compiler will emit "could not find implicit value" instead of "divergent implicit expansion" - implicit def ambiguousArbitraryComponent1[T]: Component[T] = null - implicit def ambiguousArbitraryComponent2[T]: Component[T] = null + given ambiguousArbitraryComponent1[T]: Component[T] = null + given ambiguousArbitraryComponent2[T]: Component[T] = null // TODO[scala3-port]: autoComponent (Scala 2 macro def) (L) - implicit def autoComponent[T](definition: => T)(implicit sourceInfo: SourceInfo): AutoComponent[T] = ??? + // Kept as `implicit def`: macro-stubbed and takes a by-name parameter, which a non-inline `given Conversion` cannot carry. + implicit def autoComponent[T](definition: => T)(using sourceInfo: SourceInfo): AutoComponent[T] = ??? // TODO[scala3-port]: optEmptyComponent (depends on stubbed singleton macro) (S) protected def optEmptyComponent: Component[Opt[Nothing]] = ??? @@ -65,5 +66,5 @@ trait ComponentsLowPrio { @compileTimeOnly( "implicit Component[T] => implicit T inference only works inside code passed to component/singleton macro" ) - implicit def inject[T](implicit component: Component[T]): T = sys.error("stub") + given inject[T](using component: Component[T]): T = sys.error("stub") } diff --git a/core/src/main/scala/com/avsystem/commons/meta/MacroInstances.scala b/core/src/main/scala/com/avsystem/commons/meta/MacroInstances.scala index b8a221e11..b90e7042b 100644 --- a/core/src/main/scala/com/avsystem/commons/meta/MacroInstances.scala +++ b/core/src/main/scala/com/avsystem/commons/meta/MacroInstances.scala @@ -45,5 +45,5 @@ object MacroInstances { final class materializeWith(prefix: Any, materializer: String = "materialize") extends StaticAnnotation // TODO[scala3-port]: materialize (Scala 2 macro def) (L) - implicit def materialize[Implicits, Instances]: MacroInstances[Implicits, Instances] = ??? + given materialize[Implicits, Instances]: MacroInstances[Implicits, Instances] = ??? } diff --git a/core/src/main/scala/com/avsystem/commons/meta/MetadataCompanion.scala b/core/src/main/scala/com/avsystem/commons/meta/MetadataCompanion.scala index 9c59d6268..61518c97c 100644 --- a/core/src/main/scala/com/avsystem/commons/meta/MetadataCompanion.scala +++ b/core/src/main/scala/com/avsystem/commons/meta/MetadataCompanion.scala @@ -13,9 +13,9 @@ import scala.annotation.implicitNotFound * metadata class constructor */ trait MetadataCompanion[M[_]] { - final def apply[Real](implicit metadata: M[Real]): M[Real] = metadata + final def apply[Real](using metadata: M[Real]): M[Real] = metadata - implicit final def fromFallback[Real](implicit fallback: Fallback[M[Real]]): M[Real] = fallback.value + given fromFallback[Real](using fallback: Fallback[M[Real]]): M[Real] = fallback.value final class Lazy[Real](metadata: => M[Real]) { lazy val value: M[Real] = metadata @@ -25,10 +25,10 @@ trait MetadataCompanion[M[_]] { // macro effectively turns `metadata` param into by-name param (implicit params by themselves cannot be by-name) // TODO[scala3-port]: lazyMetadata (Scala 2 macro def) (L) - implicit def lazyMetadata[Real](implicit metadata: M[Real]): Lazy[Real] = ??? + given lazyMetadata[Real](using metadata: M[Real]): Lazy[Real] = ??? @implicitNotFound("#{forNotLazy}") - implicit def notFound[T](implicit forNotLazy: ImplicitNotFound[M[T]]): ImplicitNotFound[Lazy[T]] = + given notFound[T](using forNotLazy: ImplicitNotFound[M[T]]): ImplicitNotFound[Lazy[T]] = ImplicitNotFound() } } @@ -44,9 +44,9 @@ trait MetadataCompanion[M[_]] { */ // cannot share code with MetadataCompanion because of binary compatibility problems, must copy trait BoundedMetadataCompanion[Hi, Lo <: Hi, M[_ >: Lo <: Hi]] { - final def apply[Real >: Lo <: Hi](implicit metadata: M[Real]): M[Real] = metadata + final def apply[Real >: Lo <: Hi](using metadata: M[Real]): M[Real] = metadata - implicit final def fromFallback[Real >: Lo <: Hi](implicit fallback: Fallback[M[Real]]): M[Real] = fallback.value + given fromFallback[Real >: Lo <: Hi](using fallback: Fallback[M[Real]]): M[Real] = fallback.value final class Lazy[Real >: Lo <: Hi](metadata: => M[Real]) { lazy val value: M[Real] = metadata @@ -56,10 +56,10 @@ trait BoundedMetadataCompanion[Hi, Lo <: Hi, M[_ >: Lo <: Hi]] { // macro effectively turns `metadata` param into by-name param (implicit params by themselves cannot be by-name) // TODO[scala3-port]: lazyMetadata (bounded) (Scala 2 macro def) (L) - implicit def lazyMetadata[Real >: Lo <: Hi](implicit metadata: M[Real]): Lazy[Real] = ??? + given lazyMetadata[Real >: Lo <: Hi](using metadata: M[Real]): Lazy[Real] = ??? @implicitNotFound("#{forNotLazy}") - implicit def notFound[T >: Lo <: Hi](implicit forNotLazy: ImplicitNotFound[M[T]]): ImplicitNotFound[Lazy[T]] = + given notFound[T >: Lo <: Hi](using forNotLazy: ImplicitNotFound[M[T]]): ImplicitNotFound[Lazy[T]] = ImplicitNotFound() } } diff --git a/core/src/main/scala/com/avsystem/commons/meta/OptionLike.scala b/core/src/main/scala/com/avsystem/commons/meta/OptionLike.scala index 6632da8cf..59d2e885c 100644 --- a/core/src/main/scala/com/avsystem/commons/meta/OptionLike.scala +++ b/core/src/main/scala/com/avsystem/commons/meta/OptionLike.scala @@ -53,19 +53,19 @@ final class OptionLikeImpl[O, A]( object OptionLike { type Aux[O, V] = OptionLike[O] { type Value = V } - implicit def optionOptionLike[A]: BaseOptionLike[Option[A], A] = + given optionOptionLike[A]: BaseOptionLike[Option[A], A] = new OptionLikeImpl(None, Some(_), _.isDefined, _.get, ignoreNulls = true) - implicit def optOptionLike[A]: BaseOptionLike[Opt[A], A] = + given optOptionLike[A]: BaseOptionLike[Opt[A], A] = new OptionLikeImpl(Opt.Empty, Opt.some, _.isDefined, _.get, ignoreNulls = true) - implicit def optRefOptionLike[A >: Null]: BaseOptionLike[OptRef[A], A] = + given optRefOptionLike[A >: Null]: BaseOptionLike[OptRef[A], A] = new OptionLikeImpl(OptRef.Empty, OptRef.some, _.isDefined, _.get, ignoreNulls = true) - implicit def optArgOptionLike[A]: BaseOptionLike[OptArg[A], A] = + given optArgOptionLike[A]: BaseOptionLike[OptArg[A], A] = new OptionLikeImpl(OptArg.Empty, OptArg.some, _.isDefined, _.get, ignoreNulls = true) - implicit def nOptOptionLike[A]: BaseOptionLike[NOpt[A], A] = + given nOptOptionLike[A]: BaseOptionLike[NOpt[A], A] = new OptionLikeImpl(NOpt.Empty, NOpt.some, _.isDefined, _.get, ignoreNulls = false) } @@ -82,8 +82,6 @@ object AutoOptionalParam { } trait AutoOptionalParams { - implicit def allAutoOptionalParams[T]( - implicit optionLike: OptionLike[T] - ): AutoOptionalParam[T] = AutoOptionalParam[T] + given allAutoOptionalParams[T](using optionLike: OptionLike[T]): AutoOptionalParam[T] = AutoOptionalParam[T] } object AutoOptionalParams extends AutoOptionalParams diff --git a/core/src/main/scala/com/avsystem/commons/misc/AnnotationOf.scala b/core/src/main/scala/com/avsystem/commons/misc/AnnotationOf.scala index 217e35604..0cc5c9ab5 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/AnnotationOf.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/AnnotationOf.scala @@ -10,7 +10,7 @@ import scala.annotation.implicitNotFound case class AnnotationOf[A, T](annot: A) extends AnyVal object AnnotationOf { // TODO[scala3-port]: AnnotationOf.materialize (Scala 2 macro def) (L) - implicit def materialize[A, T]: AnnotationOf[A, T] = ??? + given materialize[A, T]: AnnotationOf[A, T] = ??? } /** A typeclass which captures a possible annotation of type `A` applied on a class/trait/object associated with type @@ -20,7 +20,7 @@ object AnnotationOf { case class OptAnnotationOf[A, T](annotOpt: Opt[A]) object OptAnnotationOf { // TODO[scala3-port]: OptAnnotationOf.materialize (Scala 2 macro def) (L) - implicit def materialize[A, T]: OptAnnotationOf[A, T] = ??? + given materialize[A, T]: OptAnnotationOf[A, T] = ??? } /** A typeclass which captures all annotations of type `A` applied on a class/trait/object associated with type `T`. @@ -29,7 +29,7 @@ object OptAnnotationOf { case class AnnotationsOf[A, T](annots: List[A]) extends AnyVal object AnnotationsOf { // TODO[scala3-port]: AnnotationsOf.materialize (Scala 2 macro def) (L) - implicit def materialize[A, T]: AnnotationsOf[A, T] = ??? + given materialize[A, T]: AnnotationsOf[A, T] = ??? } /** A typeclass which serves as an evidence that an annotation of type `A` is applied on a class/trait/object associated @@ -44,7 +44,7 @@ object HasAnnotation { def create[A, T]: HasAnnotation[A, T] = reusable.asInstanceOf[HasAnnotation[A, T]] // TODO[scala3-port]: HasAnnotation.materialize (Scala 2 macro def) (L) - implicit def materialize[A, T]: HasAnnotation[A, T] = ??? + given materialize[A, T]: HasAnnotation[A, T] = ??? } /** A typeclass which may be used in an implicit constructor parameter of an abstract class. Captures an annotation of @@ -67,7 +67,7 @@ object HasAnnotation { case class SelfAnnotation[A](annot: A) extends AnyVal object SelfAnnotation { // TODO[scala3-port]: SelfAnnotation.materialize (Scala 2 macro def) (L) - implicit def materialize[A]: SelfAnnotation[A] = ??? + given materialize[A]: SelfAnnotation[A] = ??? } /** A typeclass which may be used in an implicit constructor parameter of an abstract class. Captures a possible @@ -90,7 +90,7 @@ object SelfAnnotation { case class SelfOptAnnotation[A](annotOpt: Opt[A]) object SelfOptAnnotation { // TODO[scala3-port]: SelfOptAnnotation.materialize (Scala 2 macro def) (L) - implicit def materialize[A]: SelfOptAnnotation[A] = ??? + given materialize[A]: SelfOptAnnotation[A] = ??? } /** A typeclass which may be used in an implicit constructor parameter of an abstract class. Captures all annotations of @@ -112,5 +112,5 @@ object SelfOptAnnotation { case class SelfAnnotations[A](annots: List[A]) extends AnyVal object SelfAnnotations { // TODO[scala3-port]: SelfAnnotations.materialize (Scala 2 macro def) (L) - implicit def materialize[A]: SelfAnnotations[A] = ??? + given materialize[A]: SelfAnnotations[A] = ??? } diff --git a/core/src/main/scala/com/avsystem/commons/misc/ApplierUnapplier.scala b/core/src/main/scala/com/avsystem/commons/misc/ApplierUnapplier.scala index bce4dd2dc..3f0e5734a 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/ApplierUnapplier.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/ApplierUnapplier.scala @@ -11,7 +11,7 @@ trait Applier[T] { } object Applier { // TODO[scala3-port]: Applier.materialize (Scala 2 macro def) (L) - implicit def materialize[T]: Applier[T] = ??? + given materialize[T]: Applier[T] = ??? } /** Typeclass which captures case class `unapply`/`unapplySeq` method in a raw form that returns untyped sequence of @@ -23,7 +23,7 @@ trait Unapplier[T] { } object Unapplier { // TODO[scala3-port]: Unapplier.materialize (Scala 2 macro def) (L) - implicit def materialize[T]: Unapplier[T] = ??? + given materialize[T]: Unapplier[T] = ??? } class ProductUnapplier[T <: Product] extends Unapplier[T] { @@ -35,5 +35,5 @@ abstract class ProductApplierUnapplier[T <: Product] extends ProductUnapplier[T] trait ApplierUnapplier[T] extends Applier[T] with Unapplier[T] object ApplierUnapplier { // TODO[scala3-port]: ApplierUnapplier.materialize (Scala 2 macro def) (L) - implicit def materialize[T]: ApplierUnapplier[T] = ??? + given materialize[T]: ApplierUnapplier[T] = ??? } diff --git a/core/src/main/scala/com/avsystem/commons/misc/BoxingUnboxing.scala b/core/src/main/scala/com/avsystem/commons/misc/BoxingUnboxing.scala index 7550a6150..1858b55f7 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/BoxingUnboxing.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/BoxingUnboxing.scala @@ -3,32 +3,32 @@ package misc case class Boxing[-A, +B](fun: A => B) extends AnyVal object Boxing extends LowPrioBoxing { - def fromImplicitConv[A, B](implicit conv: A => B): Boxing[A, B] = Boxing(conv) + def fromImplicitConv[A, B](using conv: A => B): Boxing[A, B] = Boxing(conv) - implicit val BooleanBoxing: Boxing[Boolean, JBoolean] = fromImplicitConv - implicit val ByteBoxing: Boxing[Byte, JByte] = fromImplicitConv - implicit val ShortBoxing: Boxing[Short, JShort] = fromImplicitConv - implicit val IntBoxing: Boxing[Int, JInteger] = fromImplicitConv - implicit val LongBoxing: Boxing[Long, JLong] = fromImplicitConv - implicit val FloatBoxing: Boxing[Float, JFloat] = fromImplicitConv - implicit val DoubleBoxing: Boxing[Double, JDouble] = fromImplicitConv + given BooleanBoxing: Boxing[Boolean, JBoolean] = fromImplicitConv + given ByteBoxing: Boxing[Byte, JByte] = fromImplicitConv + given ShortBoxing: Boxing[Short, JShort] = fromImplicitConv + given IntBoxing: Boxing[Int, JInteger] = fromImplicitConv + given LongBoxing: Boxing[Long, JLong] = fromImplicitConv + given FloatBoxing: Boxing[Float, JFloat] = fromImplicitConv + given DoubleBoxing: Boxing[Double, JDouble] = fromImplicitConv } trait LowPrioBoxing { this: Boxing.type => - implicit def nullableBoxing[A >: Null]: Boxing[A, A] = Boxing(identity) + given nullableBoxing: [A >: Null] => Boxing[A, A] = Boxing(identity) } case class Unboxing[+A, -B](fun: B => A) extends AnyVal object Unboxing extends LowPrioUnboxing { - def fromImplicitConv[A, B](implicit conv: B => A): Unboxing[A, B] = Unboxing(conv) + def fromImplicitConv[A, B](using conv: B => A): Unboxing[A, B] = Unboxing(conv) - implicit val BooleanUnboxing: Unboxing[Boolean, JBoolean] = fromImplicitConv - implicit val ByteUnboxing: Unboxing[Byte, JByte] = fromImplicitConv - implicit val ShortUnboxing: Unboxing[Short, JShort] = fromImplicitConv - implicit val IntUnboxing: Unboxing[Int, JInteger] = fromImplicitConv - implicit val LongUnboxing: Unboxing[Long, JLong] = fromImplicitConv - implicit val FloatUnboxing: Unboxing[Float, JFloat] = fromImplicitConv - implicit val DoubleUnboxing: Unboxing[Double, JDouble] = fromImplicitConv + given BooleanUnboxing: Unboxing[Boolean, JBoolean] = fromImplicitConv + given ByteUnboxing: Unboxing[Byte, JByte] = fromImplicitConv + given ShortUnboxing: Unboxing[Short, JShort] = fromImplicitConv + given IntUnboxing: Unboxing[Int, JInteger] = fromImplicitConv + given LongUnboxing: Unboxing[Long, JLong] = fromImplicitConv + given FloatUnboxing: Unboxing[Float, JFloat] = fromImplicitConv + given DoubleUnboxing: Unboxing[Double, JDouble] = fromImplicitConv } trait LowPrioUnboxing { this: Unboxing.type => - implicit def nullableUnboxing[A >: Null]: Unboxing[A, A] = Unboxing(identity) + given nullableUnboxing: [A >: Null] => Unboxing[A, A] = Unboxing(identity) } diff --git a/core/src/main/scala/com/avsystem/commons/misc/Delegation.scala b/core/src/main/scala/com/avsystem/commons/misc/Delegation.scala index dcd8f8e24..7e35b2300 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/Delegation.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/Delegation.scala @@ -9,7 +9,7 @@ trait Delegation[A, B] { object Delegation { // TODO[scala3-port]: materializeDelegation (Scala 2 macro def) (L) - implicit def materializeDelegation[A, B]: Delegation[A, B] = ??? + given materializeDelegation[A, B]: Delegation[A, B] = ??? /** Provides following syntax: * diff --git a/core/src/main/scala/com/avsystem/commons/misc/OptArg.scala b/core/src/main/scala/com/avsystem/commons/misc/OptArg.scala index 78d0e5d7c..4b8a00eb3 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/OptArg.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/OptArg.scala @@ -1,14 +1,20 @@ package com.avsystem.commons.misc +import scala.annotation.targetName + object OptArg { - /** This implicit conversion allows you to pass unwrapped values where `OptArg` is required. + /** This conversion allows you to pass unwrapped values where `OptArg` is required. Kept as `implicit def` (not a + * `given Conversion`) because a polymorphic `Conversion[A, OptArg[A]]` generates a clashing bridge: both `A` and the + * `OptArg` value class erase to `Object`. */ implicit def argToOptArg[A](value: A): OptArg[A] = OptArg(value) // additional implicits to cover most common, safe numeric promotions - implicit def intToOptArgLong(int: Int): OptArg[Long] = OptArg(int) - implicit def intToOptArgDouble(int: Int): OptArg[Double] = OptArg(int) + @targetName("intToOptArgLong") + given Conversion[Int, OptArg[Long]] = OptArg(_) + @targetName("intToOptArgDouble") + given Conversion[Int, OptArg[Double]] = OptArg(_) private object EmptyMarker extends Serializable diff --git a/core/src/main/scala/com/avsystem/commons/misc/SamCompanion.scala b/core/src/main/scala/com/avsystem/commons/misc/SamCompanion.scala index 5af10fb82..27dec936f 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/SamCompanion.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/SamCompanion.scala @@ -17,6 +17,6 @@ object SamCompanion { object ValidSam { // TODO[scala3-port]: isValidSam (Scala 2 macro def) (L) - implicit def isValidSam[T, F]: ValidSam[T, F] = ??? + given isValidSam[T, F]: ValidSam[T, F] = ??? } } diff --git a/core/src/main/scala/com/avsystem/commons/misc/SealedUtils.scala b/core/src/main/scala/com/avsystem/commons/misc/SealedUtils.scala index 917b4be4a..293dd5b4f 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/SealedUtils.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/SealedUtils.scala @@ -31,9 +31,9 @@ object SealedUtils { */ trait SealedEnumCompanion[T] { - /** Thanks to this implicit, [[SealedEnumCompanion]] and its subtraits can be used as typeclasses. + /** Thanks to this given, [[SealedEnumCompanion]] and its subtraits can be used as typeclasses. */ - implicit def evidence: this.type = this + given evidence: this.type = this /** Holds a list of all case objects of a sealed trait or class `T`. This must be implemented separately for every * sealed enum, but can be implemented simply by using the [[caseObjects]] macro. It's important to *always* state @@ -123,8 +123,8 @@ trait NamedEnumCompanion[T <: NamedEnum] extends SealedEnumCompanion[T] { ), ) - implicit lazy val keyCodec: GenKeyCodec[T] = GenKeyCodec.create(decode, _.name) - implicit lazy val codec: GenCodec[T] = GenCodec.nullableSimple[T]( + given keyCodec: GenKeyCodec[T] = GenKeyCodec.create(decode, _.name) + given codec: GenCodec[T] = GenCodec.nullableSimple[T]( input => decode(input.readString()), (output, value) => output.writeString(value.name), ) @@ -153,8 +153,7 @@ object OrderedEnum { private object reusableOrdering extends Ordering[OrderedEnum] { def compare(x: OrderedEnum, y: OrderedEnum) = Integer.compare(x.sourceInfo.offset, y.sourceInfo.offset) } - implicit def ordering[T <: OrderedEnum]: Ordering[T] = - reusableOrdering.asInstanceOf[Ordering[T]] + given ordering: [T <: OrderedEnum] => Ordering[T] = reusableOrdering.asInstanceOf[Ordering[T]] } abstract class AbstractNamedEnumCompanion[T <: NamedEnum] diff --git a/core/src/main/scala/com/avsystem/commons/misc/SelfInstance.scala b/core/src/main/scala/com/avsystem/commons/misc/SelfInstance.scala index 829b9fef4..3d0562992 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/SelfInstance.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/SelfInstance.scala @@ -5,5 +5,5 @@ package misc case class SelfInstance[C[_]](instance: C[Any]) object SelfInstance { // TODO[scala3-port]: SelfInstance.materialize (Scala 2 macro def) (L) - implicit def materialize[C[_]]: SelfInstance[C] = ??? + given materialize[C[_]]: SelfInstance[C] = ??? } diff --git a/core/src/main/scala/com/avsystem/commons/misc/SimpleClassName.scala b/core/src/main/scala/com/avsystem/commons/misc/SimpleClassName.scala index 8d1a5fa17..a3a5cffea 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/SimpleClassName.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/SimpleClassName.scala @@ -6,5 +6,5 @@ object SimpleClassName { def of[T](implicit scn: SimpleClassName[T]): String = scn.name // TODO[scala3-port]: SimpleClassName.materialize (Scala 2 macro def) (L) - implicit def materialize[T]: SimpleClassName[T] = ??? + given materialize[T]: SimpleClassName[T] = ??? } diff --git a/core/src/main/scala/com/avsystem/commons/misc/SourceInfo.scala b/core/src/main/scala/com/avsystem/commons/misc/SourceInfo.scala index bf418c3a2..dbf69059d 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/SourceInfo.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/SourceInfo.scala @@ -26,5 +26,5 @@ object SourceInfo { def apply()(implicit si: SourceInfo): SourceInfo = si // TODO[scala3-port]: SourceInfo.here (Scala 2 macro def) (L) - implicit def here: SourceInfo = ??? + given here: SourceInfo = ??? } diff --git a/core/src/main/scala/com/avsystem/commons/misc/Timestamp.scala b/core/src/main/scala/com/avsystem/commons/misc/Timestamp.scala index 5b7be55c1..46c44b2ed 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/Timestamp.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/Timestamp.scala @@ -54,6 +54,6 @@ object Timestamp { implicit def conversions(tstamp: Timestamp): TimestampConversions = new TimestampConversions(tstamp.millis) - implicit val ordering: Ordering[Timestamp] = + given ordering: Ordering[Timestamp] = Ordering.by(_.millis) } diff --git a/core/src/main/scala/com/avsystem/commons/misc/TypeString.scala b/core/src/main/scala/com/avsystem/commons/misc/TypeString.scala index a4de4ac93..f9511f919 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/TypeString.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/TypeString.scala @@ -25,16 +25,16 @@ class TypeString[T](val value: String) extends AnyVal { override def toString: String = value } object TypeString { - def apply[T](implicit ts: TypeString[T]): TypeString[T] = ts + def apply[T](using ts: TypeString[T]): TypeString[T] = ts def of[T: TypeString]: String = TypeString[T].value // TODO[scala3-port]: TypeString.materialize (Scala 2 macro def) (L) - implicit def materialize[T]: TypeString[T] = ??? + given materialize[T]: TypeString[T] = ??? - implicit val keyCodec: GenKeyCodec[TypeString[_]] = + given keyCodec: GenKeyCodec[TypeString[_]] = GenKeyCodec.create[TypeString[_]](new TypeString(_), _.value) - implicit val codec: GenCodec[TypeString[_]] = + given codec: GenCodec[TypeString[_]] = GenCodec.nonNullSimple[TypeString[_]](i => new TypeString(i.readString()), (o, ts) => o.writeString(ts.value)) } @@ -48,22 +48,22 @@ class JavaClassName[T](val value: String) extends AnyVal { override def toString: String = value } object JavaClassName extends JavaClassNameLowPrio { - def apply[T](implicit ts: JavaClassName[T]): JavaClassName[T] = ts + def apply[T](using ts: JavaClassName[T]): JavaClassName[T] = ts def of[T: JavaClassName]: String = JavaClassName[T].value - implicit val NothingClassName: JavaClassName[Nothing] = new JavaClassName("scala.runtime.Nothing$") - implicit val NothingArrayClassName: JavaClassName[Array[Nothing]] = new JavaClassName("[Lscala.runtime.Nothing$;") - implicit val UnitClassName: JavaClassName[Unit] = new JavaClassName("void") - implicit val BooleanClassName: JavaClassName[Boolean] = new JavaClassName("boolean") - implicit val ByteClassName: JavaClassName[Byte] = new JavaClassName("byte") - implicit val ShortClassName: JavaClassName[Short] = new JavaClassName("short") - implicit val IntClassName: JavaClassName[Int] = new JavaClassName("int") - implicit val LongClassName: JavaClassName[Long] = new JavaClassName("long") - implicit val FloatClassName: JavaClassName[Float] = new JavaClassName("float") - implicit val DoubleClassName: JavaClassName[Double] = new JavaClassName("double") - implicit val CharClassName: JavaClassName[Char] = new JavaClassName("char") + given NothingClassName: JavaClassName[Nothing] = new JavaClassName("scala.runtime.Nothing$") + given NothingArrayClassName: JavaClassName[Array[Nothing]] = new JavaClassName("[Lscala.runtime.Nothing$;") + given UnitClassName: JavaClassName[Unit] = new JavaClassName("void") + given BooleanClassName: JavaClassName[Boolean] = new JavaClassName("boolean") + given ByteClassName: JavaClassName[Byte] = new JavaClassName("byte") + given ShortClassName: JavaClassName[Short] = new JavaClassName("short") + given IntClassName: JavaClassName[Int] = new JavaClassName("int") + given LongClassName: JavaClassName[Long] = new JavaClassName("long") + given FloatClassName: JavaClassName[Float] = new JavaClassName("float") + given DoubleClassName: JavaClassName[Double] = new JavaClassName("double") + given CharClassName: JavaClassName[Char] = new JavaClassName("char") - implicit def arrayClassName[T: JavaClassName]: JavaClassName[Array[T]] = { + given arrayClassName[T: JavaClassName]: JavaClassName[Array[T]] = { val elementName = JavaClassName.of[T] match { case "void" => "Lscala.runtime.BoxedUnit;" case "boolean" => "Z" @@ -80,13 +80,13 @@ object JavaClassName extends JavaClassNameLowPrio { new JavaClassName("[" + elementName) } - implicit val keyCodec: GenKeyCodec[JavaClassName[_]] = + given keyCodec: GenKeyCodec[JavaClassName[_]] = GenKeyCodec.create[JavaClassName[_]](new JavaClassName(_), _.value) - implicit val codec: GenCodec[JavaClassName[_]] = + given codec: GenCodec[JavaClassName[_]] = GenCodec.nonNullSimple[JavaClassName[_]](i => new JavaClassName(i.readString()), (o, ts) => o.writeString(ts.value)) } trait JavaClassNameLowPrio { this: JavaClassName.type => // TODO[scala3-port]: JavaClassName.materialize (Scala 2 macro def) (L) - implicit def materialize[T]: JavaClassName[T] = ??? + given materialize[T]: JavaClassName[T] = ??? } diff --git a/core/src/main/scala/com/avsystem/commons/misc/TypedMap.scala b/core/src/main/scala/com/avsystem/commons/misc/TypedMap.scala index f34d3fed6..b86944e70 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/TypedMap.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/TypedMap.scala @@ -72,7 +72,7 @@ class TypedMap[K[_]](val raw: Map[K[Any], Any]) extends AnyVal { object TypedMap { case class Entry[K[_], T](pair: (K[T], T)) object Entry { - implicit def pairToEntry[K[_], T](pair: (K[T], T)): Entry[K, T] = Entry(pair) + given [K[_], T] => Conversion[(K[T], T), Entry[K, T]] = Entry(_) } def empty[K[_]]: TypedMap[K] = @@ -88,8 +88,8 @@ object TypedMap { def valueCodec[T](key: K[T]): GenCodec[T] } - implicit def typedMapCodec[K[_]](implicit keyCodec: GenKeyCodec[K[Any]], codecMapping: GenCodecMapping[K]) - : GenObjectCodec[TypedMap[K]] = + given typedMapCodec: [K[_]] => (keyCodec: GenKeyCodec[K[Any]], codecMapping: GenCodecMapping[K]) + => GenObjectCodec[TypedMap[K]] = new GenCodec.ObjectCodec[TypedMap[K]] { def nullable = false def readObject(input: ObjectInput): TypedMap[K] = { @@ -122,7 +122,7 @@ trait TypedKey[T] { def valueCodec: GenCodec[T] } object TypedKey { - implicit def codecMapping[K[X] <: TypedKey[X]]: GenCodecMapping[K] = + given codecMapping: [K[X] <: TypedKey[X]] => GenCodecMapping[K] = new GenCodecMapping[K] { def valueCodec[T](key: K[T]): GenCodec[T] = key.valueCodec } diff --git a/core/src/main/scala/com/avsystem/commons/misc/ValueEnum.scala b/core/src/main/scala/com/avsystem/commons/misc/ValueEnum.scala index 341c9f75a..718a38970 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/ValueEnum.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/ValueEnum.scala @@ -59,7 +59,7 @@ trait ValueEnum extends NamedEnum { * compatibility it's better to extend this abstract class rather than [[ValueEnum]] trait directly. See [[ValueEnum]] * documentation for more information on value-based enums. */ -abstract class AbstractValueEnum(protected implicit val enumCtx: EnumCtx) extends ValueEnum +abstract class AbstractValueEnum(using protected val enumCtx: EnumCtx) extends ValueEnum @implicitNotFound( "Value based enum must be assigned to a public, final, non-lazy val in its companion object " + @@ -123,9 +123,9 @@ trait ValueEnumCompanion[T <: ValueEnum] extends NamedEnumCompanion[T] { compani protected[this] final class ValName(val valName: String) // TODO[scala3-port]: ValueEnumCompanion.valName (Scala 2 macro def) (L) - protected[this] implicit def valName: ValName = ??? + protected[this] given valName: ValName = ??? - protected[this] implicit def enumCtx(implicit valName: ValName): EnumCtx = + protected[this] given enumCtx(using valName: ValName): EnumCtx = new Ctx(valName.valName, currentOrdinal) } diff --git a/core/src/main/scala/com/avsystem/commons/misc/ValueOf.scala b/core/src/main/scala/com/avsystem/commons/misc/ValueOf.scala index c07b04fff..aabf5dae3 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/ValueOf.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/ValueOf.scala @@ -17,8 +17,8 @@ class ValueOf[T](val value: T) extends AnyVal { @nowarn("msg=deprecated") object ValueOf { @deprecated("Use scala.valueOf[T] from the standard library (available since Scala 2.13)", "2.28.0") - def apply[T](implicit vof: ValueOf[T]): T = vof.value + def apply[T](using vof: ValueOf[T]): T = vof.value @deprecated("Use scala.ValueOf[T] from the standard library (available since Scala 2.13)", "2.28.0") - implicit def fromScala[T](implicit vof: scala.ValueOf[T]): ValueOf[T] = new ValueOf[T](vof.value) + given fromScala[T](using vof: scala.ValueOf[T]): ValueOf[T] = new ValueOf[T](vof.value) } diff --git a/core/src/main/scala/com/avsystem/commons/serialization/GenCodec.scala b/core/src/main/scala/com/avsystem/commons/serialization/GenCodec.scala index 97c3eef3b..04e63b366 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/GenCodec.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/GenCodec.scala @@ -307,8 +307,8 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { def nullable: Boolean = wrapped.nullable } - implicit def fromTransparentWrapping[R, T](implicit tw: TransparentWrapping[R, T], wrapped: OOOFieldsObjectCodec[R]) - : OOOFieldsObjectCodec[T] = + given fromTransparentWrapping: [R, T] => (tw: TransparentWrapping[R, T]) => (wrapped: OOOFieldsObjectCodec[R]) + => OOOFieldsObjectCodec[T] = new Transformed(wrapped, tw.unwrap, tw.wrap) } @@ -348,53 +348,53 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { private def notNull = throw new ReadFailure("not null") - implicit lazy val NothingCodec: GenCodec[Nothing] = + given NothingCodec: GenCodec[Nothing] = create[Nothing](_ => throw new ReadFailure("read Nothing"), (_, _) => throw new WriteFailure("write Nothing")) - implicit lazy val NullCodec: GenCodec[Null] = + given NullCodec: GenCodec[Null] = create[Null](i => if (i.readNull()) null else notNull, (o, _) => o.writeNull()) - implicit lazy val UnitCodec: GenCodec[Unit] = + given UnitCodec: GenCodec[Unit] = create[Unit](i => if (i.readNull()) () else notNull, (o, _) => o.writeNull()) - implicit lazy val VoidCodec: GenCodec[Void] = + given VoidCodec: GenCodec[Void] = create[Void](i => if (i.readNull()) null else notNull, (o, _) => o.writeNull()) - implicit lazy val BooleanCodec: GenCodec[Boolean] = nonNullSimple(_.readBoolean(), _ writeBoolean _) - implicit lazy val CharCodec: GenCodec[Char] = nonNullSimple(_.readChar(), _ writeChar _) - implicit lazy val ByteCodec: GenCodec[Byte] = nonNullSimple(_.readByte(), _ writeByte _) - implicit lazy val ShortCodec: GenCodec[Short] = nonNullSimple(_.readShort(), _ writeShort _) - implicit lazy val IntCodec: GenCodec[Int] = nonNullSimple(_.readInt(), _ writeInt _) - implicit lazy val LongCodec: GenCodec[Long] = nonNullSimple(_.readLong(), _ writeLong _) - implicit lazy val FloatCodec: GenCodec[Float] = nonNullSimple(_.readFloat(), _ writeFloat _) - implicit lazy val DoubleCodec: GenCodec[Double] = nonNullSimple(_.readDouble(), _ writeDouble _) - implicit lazy val BigIntCodec: GenCodec[BigInt] = nullableSimple(_.readBigInt(), _ writeBigInt _) - implicit lazy val BigDecimalCodec: GenCodec[BigDecimal] = nullableSimple(_.readBigDecimal(), _ writeBigDecimal _) - - implicit lazy val JBooleanCodec: GenCodec[JBoolean] = nullableSimple(_.readBoolean(), _ writeBoolean _) - implicit lazy val JCharacterCodec: GenCodec[JCharacter] = nullableSimple(_.readChar(), _ writeChar _) - implicit lazy val JByteCodec: GenCodec[JByte] = nullableSimple(_.readByte(), _ writeByte _) - implicit lazy val JShortCodec: GenCodec[JShort] = nullableSimple(_.readShort(), _ writeShort _) - implicit lazy val JIntegerCodec: GenCodec[JInteger] = nullableSimple(_.readInt(), _ writeInt _) - implicit lazy val JLongCodec: GenCodec[JLong] = nullableSimple(_.readLong(), _ writeLong _) - implicit lazy val JFloatCodec: GenCodec[JFloat] = nullableSimple(_.readFloat(), _ writeFloat _) - implicit lazy val JDoubleCodec: GenCodec[JDouble] = nullableSimple(_.readDouble(), _ writeDouble _) - implicit lazy val JBigIntegerCodec: GenCodec[JBigInteger] = + given BooleanCodec: GenCodec[Boolean] = nonNullSimple(_.readBoolean(), _ writeBoolean _) + given CharCodec: GenCodec[Char] = nonNullSimple(_.readChar(), _ writeChar _) + given ByteCodec: GenCodec[Byte] = nonNullSimple(_.readByte(), _ writeByte _) + given ShortCodec: GenCodec[Short] = nonNullSimple(_.readShort(), _ writeShort _) + given IntCodec: GenCodec[Int] = nonNullSimple(_.readInt(), _ writeInt _) + given LongCodec: GenCodec[Long] = nonNullSimple(_.readLong(), _ writeLong _) + given FloatCodec: GenCodec[Float] = nonNullSimple(_.readFloat(), _ writeFloat _) + given DoubleCodec: GenCodec[Double] = nonNullSimple(_.readDouble(), _ writeDouble _) + given BigIntCodec: GenCodec[BigInt] = nullableSimple(_.readBigInt(), _ writeBigInt _) + given BigDecimalCodec: GenCodec[BigDecimal] = nullableSimple(_.readBigDecimal(), _ writeBigDecimal _) + + given JBooleanCodec: GenCodec[JBoolean] = nullableSimple(_.readBoolean(), _ writeBoolean _) + given JCharacterCodec: GenCodec[JCharacter] = nullableSimple(_.readChar(), _ writeChar _) + given JByteCodec: GenCodec[JByte] = nullableSimple(_.readByte(), _ writeByte _) + given JShortCodec: GenCodec[JShort] = nullableSimple(_.readShort(), _ writeShort _) + given JIntegerCodec: GenCodec[JInteger] = nullableSimple(_.readInt(), _ writeInt _) + given JLongCodec: GenCodec[JLong] = nullableSimple(_.readLong(), _ writeLong _) + given JFloatCodec: GenCodec[JFloat] = nullableSimple(_.readFloat(), _ writeFloat _) + given JDoubleCodec: GenCodec[JDouble] = nullableSimple(_.readDouble(), _ writeDouble _) + given JBigIntegerCodec: GenCodec[JBigInteger] = nullableSimple(_.readBigInt().bigInteger, (o, v) => o.writeBigInt(BigInt(v))) - implicit lazy val JBigDecimalCodec: GenCodec[JBigDecimal] = + given JBigDecimalCodec: GenCodec[JBigDecimal] = nullableSimple(_.readBigDecimal().bigDecimal, (o, v) => o.writeBigDecimal(BigDecimal(v))) - implicit lazy val JDateCodec: GenCodec[JDate] = + given JDateCodec: GenCodec[JDate] = nullableSimple(i => new JDate(i.readTimestamp()), (o, d) => o.writeTimestamp(d.getTime)) - implicit lazy val StringCodec: GenCodec[String] = + given StringCodec: GenCodec[String] = nullableSimple(_.readString(), _ writeString _) - implicit lazy val SymbolCodec: GenCodec[Symbol] = + given SymbolCodec: GenCodec[Symbol] = nullableSimple(i => Symbol(i.readString()), (o, s) => o.writeString(s.name)) - implicit lazy val ByteArrayCodec: GenCodec[Array[Byte]] = + given ByteArrayCodec: GenCodec[Array[Byte]] = nullableSimple(_.readBinary(), _ writeBinary _) - implicit lazy val UuidCodec: GenCodec[UUID] = + given UuidCodec: GenCodec[UUID] = nullableSimple(i => UUID.fromString(i.readString()), (o, v) => o.writeString(v.toString)) - implicit lazy val TimestampCodec: GenCodec[Timestamp] = + given TimestampCodec: GenCodec[Timestamp] = GenCodec.nonNullSimple(i => Timestamp(i.readTimestamp()), (o, t) => o.writeTimestamp(t.millis)) - implicit lazy val BytesCodec: GenCodec[Bytes] = + given BytesCodec: GenCodec[Bytes] = GenCodec.nullableSimple(i => Bytes(i.readBinary()), (o, b) => o.writeBinary(b.bytes)) private implicit class IterableOps[A](private val coll: BIterable[A]) extends AnyVal { @@ -467,7 +467,7 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { } } - implicit def arrayCodec[T: ClassTag: GenCodec]: GenCodec[Array[T]] = + given arrayCodec: [T: ClassTag: GenCodec] => GenCodec[Array[T]] = nullableList[Array[T]]( _.iterator(read[T]).toArray[T], (lo, arr) => { @@ -483,58 +483,51 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { // these are covered by the generic `seqCodec` and `setCodec` but making them explicit may be easier // for the compiler and also make IntelliJ less confused - implicit def bseqCodec[T: GenCodec]: GenCodec[BSeq[T]] = - seqCodec[BSeq, T](using GenCodec[T], implicitly[Factory[T, List[T]]]) - implicit def iseqCodec[T: GenCodec]: GenCodec[ISeq[T]] = - seqCodec[ISeq, T](using GenCodec[T], implicitly[Factory[T, List[T]]]) - implicit def mseqCodec[T: GenCodec]: GenCodec[MSeq[T]] = seqCodec[MSeq, T] - implicit def bindexedSeqCodec[T: GenCodec]: GenCodec[BIndexedSeq[T]] = seqCodec[BIndexedSeq, T] - implicit def iindexedSeqCodec[T: GenCodec]: GenCodec[IIndexedSeq[T]] = seqCodec[IIndexedSeq, T] - implicit def mindexedSeqCodec[T: GenCodec]: GenCodec[MIndexedSeq[T]] = seqCodec[MIndexedSeq, T] - implicit def listCodec[T: GenCodec]: GenCodec[List[T]] = seqCodec[List, T] - implicit def vectorCodec[T: GenCodec]: GenCodec[Vector[T]] = seqCodec[Vector, T] - implicit def bsetCodec[T: GenCodec]: GenCodec[BSet[T]] = setCodec[BSet, T] - implicit def isetCodec[T: GenCodec]: GenCodec[ISet[T]] = setCodec[ISet, T] - implicit def msetCodec[T: GenCodec]: GenCodec[MSet[T]] = setCodec[MSet, T] - implicit def ihashSetCodec[T: GenCodec]: GenCodec[IHashSet[T]] = setCodec[IHashSet, T] - implicit def mhashSetCodec[T: GenCodec]: GenCodec[MHashSet[T]] = setCodec[MHashSet, T] + given bseqCodec[T: GenCodec]: GenCodec[BSeq[T]] = + seqCodec[BSeq, T](using GenCodec[T], summon[Factory[T, List[T]]]) + given iseqCodec[T: GenCodec]: GenCodec[ISeq[T]] = + seqCodec[ISeq, T](using GenCodec[T], summon[Factory[T, List[T]]]) + given mseqCodec[T: GenCodec]: GenCodec[MSeq[T]] = seqCodec[MSeq, T] + given bindexedSeqCodec[T: GenCodec]: GenCodec[BIndexedSeq[T]] = seqCodec[BIndexedSeq, T] + given iindexedSeqCodec[T: GenCodec]: GenCodec[IIndexedSeq[T]] = seqCodec[IIndexedSeq, T] + given mindexedSeqCodec[T: GenCodec]: GenCodec[MIndexedSeq[T]] = seqCodec[MIndexedSeq, T] + given listCodec[T: GenCodec]: GenCodec[List[T]] = seqCodec[List, T] + given vectorCodec[T: GenCodec]: GenCodec[Vector[T]] = seqCodec[Vector, T] + given bsetCodec[T: GenCodec]: GenCodec[BSet[T]] = setCodec[BSet, T] + given isetCodec[T: GenCodec]: GenCodec[ISet[T]] = setCodec[ISet, T] + given msetCodec[T: GenCodec]: GenCodec[MSet[T]] = setCodec[MSet, T] + given ihashSetCodec[T: GenCodec]: GenCodec[IHashSet[T]] = setCodec[IHashSet, T] + given mhashSetCodec[T: GenCodec]: GenCodec[MHashSet[T]] = setCodec[MHashSet, T] // seqCodec, setCodec, jCollectionCodec, mapCodec, jMapCodec, fallbackMapCodec and fallbackJMapCodec // have these weird return types (e.g. GenCodec[C[T] with BSeq[T]] instead of just GenCodec[C[T]]) because it's a // workaround for https://groups.google.com/forum/#!topic/scala-user/O_fkaChTtg4 - implicit def seqCodec[C[X] <: BSeq[X], T: GenCodec]( - implicit fac: Factory[T, C[T]] - ): GenCodec[C[T] with BSeq[T]] = + given seqCodec: [C[X] <: BSeq[X], T: GenCodec] => (fac: Factory[T, C[T]]) => GenCodec[C[T] with BSeq[T]] = nullableList[C[T] with BSeq[T]](_.collectTo[T, C[T]], (lo, c) => c.writeToList(lo)) - implicit def setCodec[C[X] <: BSet[X], T: GenCodec]( - implicit fac: Factory[T, C[T]] - ): GenCodec[C[T] with BSet[T]] = + given setCodec: [C[X] <: BSet[X], T: GenCodec] => (fac: Factory[T, C[T]]) => GenCodec[C[T] with BSet[T]] = nullableList[C[T] with BSet[T]](_.collectTo[T, C[T]], (lo, c) => c.writeToList(lo)) - implicit def jCollectionCodec[C[X] <: JCollection[X], T: GenCodec]( - implicit cbf: JFactory[T, C[T]] - ): GenCodec[C[T] with JCollection[T]] = + given jCollectionCodec: [C[X] <: JCollection[X], T: GenCodec] => (cbf: JFactory[T, C[T]]) + => GenCodec[C[T] with JCollection[T]] = nullableList[C[T]](_.collectTo[T, C[T]], (lo, c) => c.asScala.writeToList(lo)) - implicit def mapCodec[M[X, Y] <: BMap[X, Y], K: GenKeyCodec, V: GenCodec]( - implicit fac: Factory[(K, V), M[K, V]] - ): GenObjectCodec[M[K, V]] = + given mapCodec: [M[X, Y] <: BMap[X, Y], K: GenKeyCodec, V: GenCodec] => (fac: Factory[(K, V), M[K, V]]) + => GenObjectCodec[M[K, V]] = nullableObject[M[K, V]]( _.collectTo[K, V, M[K, V]], (oo, value) => value.writeToObject(oo), ) - implicit def jMapCodec[M[X, Y] <: JMap[X, Y], K: GenKeyCodec, V: GenCodec]( - implicit cbf: JFactory[(K, V), M[K, V]] - ): GenObjectCodec[M[K, V]] = + given jMapCodec: [M[X, Y] <: JMap[X, Y], K: GenKeyCodec, V: GenCodec] => (cbf: JFactory[(K, V), M[K, V]]) + => GenObjectCodec[M[K, V]] = nullableObject[M[K, V]]( _.collectTo[K, V, M[K, V]], (oo, value) => value.asScala.writeToObject(oo), ) - implicit def optionCodec[T: GenCodec]: GenCodec[Option[T]] = create[Option[T]]( + given optionCodec: [T: GenCodec] => GenCodec[Option[T]] = create[Option[T]]( input => if (input.legacyOptionEncoding) { val li = input.readList() @@ -555,10 +548,10 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { }, ) - implicit def nOptCodec[T: GenCodec]: GenCodec[NOpt[T]] = + given nOptCodec: [T: GenCodec] => GenCodec[NOpt[T]] = new Transformed[NOpt[T], Option[T]](optionCodec[T], _.toOption, _.toNOpt) - implicit def optCodec[T: GenCodec]: GenCodec[Opt[T]] = + given optCodec: [T: GenCodec] => GenCodec[Opt[T]] = create[Opt[T]]( i => if (i.readNull()) Opt.Empty else Opt(read[T](i)), (o, vo) => @@ -568,13 +561,13 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { }, ) - implicit def optArgCodec[T: GenCodec]: GenCodec[OptArg[T]] = + given optArgCodec: [T: GenCodec] => GenCodec[OptArg[T]] = new Transformed[OptArg[T], Opt[T]](optCodec[T], _.toOpt, _.toOptArg) - implicit def optRefCodec[T >: Null: GenCodec]: GenCodec[OptRef[T]] = + given optRefCodec: [T >: Null: GenCodec] => GenCodec[OptRef[T]] = new Transformed[OptRef[T], Opt[T]](optCodec[T], _.toOpt, _.toOptRef) - implicit def eitherCodec[A: GenCodec, B: GenCodec]: GenCodec[Either[A, B]] = nullableObject( + given eitherCodec: [A: GenCodec, B: GenCodec] => GenCodec[Either[A, B]] = nullableObject( oi => { val fi = oi.nextField() fi.fieldName match { @@ -592,17 +585,17 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { }, ) - implicit def jEnumCodec[E <: Enum[E]: ClassTag]: GenCodec[E] = nullableSimple( + given jEnumCodec: [E <: Enum[E]: ClassTag] => GenCodec[E] = nullableSimple( in => Enum.valueOf(classTag[E].runtimeClass.asInstanceOf[Class[E]], in.readString()), (out, value) => out.writeString(value.name), ) // Warning! Changing the order of implicit params of this method causes divergent implicit expansion (WTF?) - implicit def fromTransparentWrapping[R, T](implicit tw: TransparentWrapping[R, T], wrappedCodec: GenCodec[R]) - : GenCodec[T] = + given fromTransparentWrapping + : [R, T] => (tw: TransparentWrapping[R, T]) => (wrappedCodec: GenCodec[R]) => GenCodec[T] = new Transformed(wrappedCodec, tw.unwrap, tw.wrap) - implicit def fromFallback[T](implicit fallback: Fallback[GenCodec[T]]): GenCodec[T] = + given fromFallback: [T] => (fallback: Fallback[GenCodec[T]]) => GenCodec[T] = fallback.value } @@ -611,5 +604,5 @@ trait RecursiveAutoCodecs { this: GenCodec.type => def materializeRecursively[T]: GenCodec[T] = ??? // TODO[scala3-port]: GenCodec.materializeImplicitly (Scala 2 macro def) (L) - implicit def materializeImplicitly[T](implicit allow: AllowImplicitMacro[GenCodec[T]]): GenCodec[T] = ??? + given materializeImplicitly: [T] => (allow: AllowImplicitMacro[GenCodec[T]]) => GenCodec[T] = ??? } diff --git a/core/src/main/scala/com/avsystem/commons/serialization/GenKeyCodec.scala b/core/src/main/scala/com/avsystem/commons/serialization/GenKeyCodec.scala index e57d4f574..20021057b 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/GenKeyCodec.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/GenKeyCodec.scala @@ -60,37 +60,38 @@ object GenKeyCodec { } } - implicit lazy val BooleanKeyCodec: GenKeyCodec[Boolean] = create(_.toBoolean, _.toString) - implicit lazy val CharKeyCodec: GenKeyCodec[Char] = create(_.charAt(0), _.toString) - implicit lazy val ByteKeyCodec: GenKeyCodec[Byte] = create(_.toByte, _.toString) - implicit lazy val ShortKeyCodec: GenKeyCodec[Short] = create(_.toShort, _.toString) - implicit lazy val IntKeyCodec: GenKeyCodec[Int] = create(_.toInt, _.toString) - implicit lazy val LongKeyCodec: GenKeyCodec[Long] = create(_.toLong, _.toString) - implicit lazy val BigIntKeyCodec: GenKeyCodec[BigInt] = create(BigInt(_), _.toString) - - implicit lazy val JBooleanKeyCodec: GenKeyCodec[JBoolean] = create(_.toBoolean, _.toString) - implicit lazy val JCharacterKeyCodec: GenKeyCodec[JCharacter] = create(_.charAt(0), _.toString) - implicit lazy val JByteKeyCodec: GenKeyCodec[JByte] = create(_.toByte, _.toString) - implicit lazy val JShortKeyCodec: GenKeyCodec[JShort] = create(_.toShort, _.toString) - implicit lazy val JIntKeyCodec: GenKeyCodec[JInteger] = create(_.toInt, _.toString) - implicit lazy val JLongKeyCodec: GenKeyCodec[JLong] = create(_.toLong, _.toString) - implicit lazy val JBigIntegerKeyCodec: GenKeyCodec[JBigInteger] = create(new JBigInteger(_), _.toString) - - implicit lazy val StringKeyCodec: GenKeyCodec[String] = create(identity, identity) - implicit lazy val SymbolKeyCodec: GenKeyCodec[Symbol] = create(Symbol(_), _.name) - implicit lazy val UuidCodec: GenKeyCodec[UUID] = create(UUID.fromString, _.toString) - - implicit lazy val TimestampKeyCodec: GenKeyCodec[Timestamp] = GenKeyCodec.create(Timestamp.parse, _.toString) - implicit lazy val BytesKeyCodec: GenKeyCodec[Bytes] = GenKeyCodec.create(Bytes.fromBase64(_), _.base64) - - implicit def jEnumKeyCodec[E <: Enum[E]](implicit ct: ClassTag[E]): GenKeyCodec[E] = + given BooleanKeyCodec: GenKeyCodec[Boolean] = create(_.toBoolean, _.toString) + given CharKeyCodec: GenKeyCodec[Char] = create(_.charAt(0), _.toString) + given ByteKeyCodec: GenKeyCodec[Byte] = create(_.toByte, _.toString) + given ShortKeyCodec: GenKeyCodec[Short] = create(_.toShort, _.toString) + given IntKeyCodec: GenKeyCodec[Int] = create(_.toInt, _.toString) + given LongKeyCodec: GenKeyCodec[Long] = create(_.toLong, _.toString) + given BigIntKeyCodec: GenKeyCodec[BigInt] = create(BigInt(_), _.toString) + + given JBooleanKeyCodec: GenKeyCodec[JBoolean] = create(_.toBoolean, _.toString) + given JCharacterKeyCodec: GenKeyCodec[JCharacter] = create(_.charAt(0), _.toString) + given JByteKeyCodec: GenKeyCodec[JByte] = create(_.toByte, _.toString) + given JShortKeyCodec: GenKeyCodec[JShort] = create(_.toShort, _.toString) + given JIntKeyCodec: GenKeyCodec[JInteger] = create(_.toInt, _.toString) + given JLongKeyCodec: GenKeyCodec[JLong] = create(_.toLong, _.toString) + given JBigIntegerKeyCodec: GenKeyCodec[JBigInteger] = create(new JBigInteger(_), _.toString) + + given StringKeyCodec: GenKeyCodec[String] = create(identity, identity) + given SymbolKeyCodec: GenKeyCodec[Symbol] = create(Symbol(_), _.name) + given UUIDKeyCodec: GenKeyCodec[UUID] = create(UUID.fromString, _.toString) + + given TimestampKeyCodec: GenKeyCodec[Timestamp] = GenKeyCodec.create(Timestamp.parse, _.toString) + given BytesKeyCodec: GenKeyCodec[Bytes] = GenKeyCodec.create(Bytes.fromBase64(_), _.base64) + + given jEnumKeyCodec: [E <: Enum[E]] => (ct: ClassTag[E]) => GenKeyCodec[E] = GenKeyCodec.create( string => Enum.valueOf(ct.runtimeClass.asInstanceOf[Class[E]], string), e => e.name(), ) // Warning! Changing the order of implicit params of this method causes divergent implicit expansion (WTF?) - implicit def fromTransparentWrapping[R, T](implicit tw: TransparentWrapping[R, T], wrappedCodec: GenKeyCodec[R]) - : GenKeyCodec[T] = + given fromTransparentWrapping + : [R, T] => (tw: TransparentWrapping[R, T]) => (wrappedCodec: GenKeyCodec[R]) => GenKeyCodec[T] = new Transformed(wrappedCodec, tw.unwrap, tw.wrap) + } diff --git a/core/src/main/scala/com/avsystem/commons/serialization/GenObjectCodec.scala b/core/src/main/scala/com/avsystem/commons/serialization/GenObjectCodec.scala index 08a0c2260..b1500adb9 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/GenObjectCodec.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/GenObjectCodec.scala @@ -53,7 +53,7 @@ object GenObjectCodec { } // Warning! Changing the order of implicit params of this method causes divergent implicit expansion (WTF?) - implicit def fromTransparentWrapping[R, T](implicit tw: TransparentWrapping[R, T], wrappedCodec: GenObjectCodec[R]) + given fromTransparentWrapping[R, T](using tw: TransparentWrapping[R, T], wrappedCodec: GenObjectCodec[R]) : GenObjectCodec[T] = new Transformed(wrappedCodec, tw.unwrap, tw.wrap) diff --git a/core/src/main/scala/com/avsystem/commons/serialization/GenRef.scala b/core/src/main/scala/com/avsystem/commons/serialization/GenRef.scala index 4592a49a7..8aa941684 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/GenRef.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/GenRef.scala @@ -19,7 +19,7 @@ object RawRef { case class Composite(left: RawRef, right: RawRef) extends RawRef case object Identity extends RawRef - implicit val codec: GenCodec[RawRef] = GenCodec.materialize[RawRef] + given codec: GenCodec[RawRef] = GenCodec.materialize[RawRef] def create[S]: Creator[S] = new Creator[S] {} @@ -30,7 +30,7 @@ object RawRef { } object SimpleRawRef { - implicit val codec: GenCodec[SimpleRawRef] = GenCodec.materialize[SimpleRawRef] + given codec: GenCodec[SimpleRawRef] = GenCodec.materialize[SimpleRawRef] } case class GenRef[-S, +T](fun: S => T, rawRef: RawRef) { diff --git a/core/src/main/scala/com/avsystem/commons/serialization/HasGenCodec.scala b/core/src/main/scala/com/avsystem/commons/serialization/HasGenCodec.scala index c75b3977a..108d0c4f6 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/HasGenCodec.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/HasGenCodec.scala @@ -14,19 +14,19 @@ import scala.annotation.nowarn * etc. */ abstract class HasGenCodec[T](implicit macroCodec: MacroInstances[Unit, () => GenCodec[T]]) { - implicit val codec: GenCodec[T] = macroCodec((), this).apply() + given codec: GenCodec[T] = macroCodec((), this).apply() } /** Like [[HasGenCodec]] but materializes an [[ApplyUnapplyCodec]] instead of just [[GenCodec]]. */ abstract class HasApplyUnapplyCodec[T](implicit macroCodec: MacroInstances[Unit, () => ApplyUnapplyCodec[T]]) { - implicit val codec: ApplyUnapplyCodec[T] = macroCodec((), this).apply() + given codec: ApplyUnapplyCodec[T] = macroCodec((), this).apply() } /** Like [[HasGenCodec]] but materializes a [[GenObjectCodec]] instead of just [[GenCodec]]. */ abstract class HasGenObjectCodec[T](implicit macroCodec: MacroInstances[Unit, () => GenObjectCodec[T]]) { - implicit val codec: GenObjectCodec[T] = macroCodec((), this).apply() + given codec: GenObjectCodec[T] = macroCodec((), this).apply() } /** A version of [[HasGenCodec]] which injects additional implicits into macro materialization. Implicits are imported @@ -41,7 +41,7 @@ abstract class HasGenCodecWithDeps[D, T]( private[serialization] def this(applyUnapplyProvider: ValueOf[D], instances: MacroInstances[D, () => GenCodec[T]]) = this()(instances, applyUnapplyProvider.toScala) - implicit val codec: GenCodec[T] = macroCodec(deps.value, this).apply() + given codec: GenCodec[T] = macroCodec(deps.value, this).apply() } /** A version of [[HasApplyUnapplyCodecWithDeps]] which injects additional implicits into macro materialization. @@ -59,7 +59,7 @@ abstract class HasApplyUnapplyCodecWithDeps[D, T]( instances: MacroInstances[D, () => ApplyUnapplyCodec[T]], ) = this()(instances, applyUnapplyProvider.toScala) - implicit val codec: ApplyUnapplyCodec[T] = macroCodec(deps.value, this).apply() + given codec: ApplyUnapplyCodec[T] = macroCodec(deps.value, this).apply() } /** A version of [[HasGenObjectCodec]] which injects additional implicits into macro materialization. Implicits are @@ -77,7 +77,7 @@ abstract class HasGenObjectCodecWithDeps[D, T]( instances: MacroInstances[D, () => GenObjectCodec[T]], ) = this()(instances, applyUnapplyProvider.toScala) - implicit val codec: GenObjectCodec[T] = macroCodec(deps.value, this).apply() + given codec: GenObjectCodec[T] = macroCodec(deps.value, this).apply() } trait PolyCodec[C[_]] { @@ -87,7 +87,7 @@ trait PolyCodec[C[_]] { /** Like [[HasGenCodec]] but for parameterized (generic) data types. */ abstract class HasPolyGenCodec[C[_]](implicit macroCodec: MacroInstances[Unit, PolyCodec[C]]) { - implicit def codec[T: GenCodec]: GenCodec[C[T]] = macroCodec((), this).codec + given codec[T: GenCodec]: GenCodec[C[T]] = macroCodec((), this).codec } /** A version of [[HasPolyGenCodec]] which injects additional implicits into macro materialization. Implicits are @@ -103,7 +103,7 @@ abstract class HasPolyGenCodecWithDeps[D, C[_]]( private[serialization] def this(applyUnapplyProvider: ValueOf[D], instances: MacroInstances[D, PolyCodec[C]]) = this()(instances, applyUnapplyProvider.toScala) - implicit def codec[T: GenCodec]: GenCodec[C[T]] = macroCodec(deps.value, this).codec + given codec[T: GenCodec]: GenCodec[C[T]] = macroCodec(deps.value, this).codec } trait PolyObjectCodec[C[_]] { @@ -113,7 +113,7 @@ trait PolyObjectCodec[C[_]] { /** Like [[HasGenObjectCodec]] but for parameterized (generic) data types. */ abstract class HasPolyGenObjectCodec[C[_]](implicit macroCodec: MacroInstances[Unit, PolyObjectCodec[C]]) { - implicit def codec[T: GenCodec]: GenObjectCodec[C[T]] = macroCodec((), this).codec + given codec[T: GenCodec]: GenObjectCodec[C[T]] = macroCodec((), this).codec } /** A version of [[HasPolyGenObjectCodec]] which injects additional implicits into macro materialization. Implicits are @@ -129,7 +129,7 @@ abstract class HasPolyGenObjectCodecWithDeps[D, C[_]]( private[serialization] def this(applyUnapplyProvider: ValueOf[D], instances: MacroInstances[D, PolyObjectCodec[C]]) = this()(instances, applyUnapplyProvider.toScala) - implicit def codec[T: GenCodec]: GenObjectCodec[C[T]] = macroCodec(deps.value, this).codec + given codec[T: GenCodec]: GenObjectCodec[C[T]] = macroCodec(deps.value, this).codec } trait GadtCodec[C[_]] { @@ -141,8 +141,8 @@ trait GadtCodec[C[_]] { */ abstract class HasGadtCodec[C[_]](implicit macroCodec: MacroInstances[Unit, GadtCodec[C]]) { // TODO[scala3-port]: C[_] existential narrowed to C[Any] (Scala 3 forbids HKT wildcard application) (S) - implicit lazy val wildcardCodec: GenCodec[C[Any]] = macroCodec((), this).codec[Any].asInstanceOf[GenCodec[C[Any]]] - implicit def codec[T]: GenCodec[C[T]] = wildcardCodec.asInstanceOf[GenCodec[C[T]]] + given wildcardCodec: GenCodec[C[Any]] = macroCodec((), this).codec[Any].asInstanceOf[GenCodec[C[Any]]] + given codec[T]: GenCodec[C[T]] = wildcardCodec.asInstanceOf[GenCodec[C[T]]] } trait RecursiveCodec[T] { @@ -153,7 +153,7 @@ trait RecursiveCodec[T] { /** Like [[HasGenCodec]] but uses [[GenCodec.materializeRecursively]] for materialization. */ abstract class HasRecursiveGenCodec[T](implicit instances: MacroInstances[Unit, RecursiveCodec[T]]) { - implicit lazy val codec: GenCodec[T] = instances((), this).codec + given codec: GenCodec[T] = instances((), this).codec } trait CodecWithKeyCodec[T] { @@ -166,8 +166,8 @@ trait CodecWithKeyCodec[T] { * that wraps exactly one field for which [[GenKeyCodec]] exists. */ abstract class HasGenAndKeyCodec[T](implicit instances: MacroInstances[Unit, CodecWithKeyCodec[T]]) { - implicit lazy val codec: GenCodec[T] = instances((), this).codec - implicit lazy val keyCodec: GenKeyCodec[T] = instances((), this).keyCodec + given codec: GenCodec[T] = instances((), this).codec + given keyCodec: GenKeyCodec[T] = instances((), this).keyCodec } trait AUCodec[AU, T] { @@ -189,6 +189,6 @@ abstract class HasGenCodecFromAU[AU, T]( private[serialization] def this(applyUnapplyProvider: ValueOf[AU], instances: MacroInstances[Unit, AUCodec[AU, T]]) = this()(instances, applyUnapplyProvider.toScala) - implicit final lazy val codec: GenCodec[T] = + given codec: GenCodec[T] = instances((), this).codec(applyUnapplyProvider.value) } diff --git a/core/src/main/scala/com/avsystem/commons/serialization/SerializationName.scala b/core/src/main/scala/com/avsystem/commons/serialization/SerializationName.scala index 8b6a9bfe1..4e570d352 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/SerializationName.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/SerializationName.scala @@ -5,12 +5,12 @@ import com.avsystem.commons.misc.{AnnotationOf, SimpleClassName} case class SerializationName[T](name: String) extends AnyVal object SerializationName extends SerializationNameLowPrio { - def of[T](implicit sn: SerializationName[T]): String = sn.name + def of[T](using sn: SerializationName[T]): String = sn.name - implicit def fromNameAnnot[T](implicit nameAnnot: AnnotationOf[name, T]): SerializationName[T] = + given fromNameAnnot[T](using nameAnnot: AnnotationOf[name, T]): SerializationName[T] = SerializationName(nameAnnot.annot.name) } trait SerializationNameLowPrio { this: SerializationName.type => - implicit def fromSimpleClassName[T: SimpleClassName]: SerializationName[T] = + given fromSimpleClassName[T: SimpleClassName]: SerializationName[T] = SerializationName(SimpleClassName.of[T]) } diff --git a/core/src/main/scala/com/avsystem/commons/serialization/TransparentWrapperCompanion.scala b/core/src/main/scala/com/avsystem/commons/serialization/TransparentWrapperCompanion.scala index c4298720a..04556ea77 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/TransparentWrapperCompanion.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/TransparentWrapperCompanion.scala @@ -26,7 +26,7 @@ object TransparentWrapping { * [[transparent]] annotation where possible. */ abstract class TransparentWrapperCompanion[R, T] extends TransparentWrapping[R, T] with (R => T) { - implicit def self: TransparentWrapping[R, T] = this + given self: TransparentWrapping[R, T] = this def apply(r: R): T def unapply(t: T): Option[R] @@ -34,7 +34,7 @@ abstract class TransparentWrapperCompanion[R, T] extends TransparentWrapping[R, final def wrap(r: R): T = apply(r) final def unwrap(t: T): R = unapply(t).getOrElse(throw new NoSuchElementException(s"unapply for $t failed")) - implicit def ordering(implicit wrappedOrdering: Ordering[R]): Ordering[T] = + given ordering(using wrappedOrdering: Ordering[R]): Ordering[T] = Ordering.by(unwrap) } diff --git a/core/src/main/scala/com/avsystem/commons/serialization/TupleGenCodecs.scala b/core/src/main/scala/com/avsystem/commons/serialization/TupleGenCodecs.scala index da9b9f70a..663dc03f2 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/TupleGenCodecs.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/TupleGenCodecs.scala @@ -5,23 +5,22 @@ trait TupleGenCodecs { this: GenCodec.type => // TODO[scala3-port]: mkTupleCodec (Scala 2 macro def) (L) private def mkTupleCodec[T](elementCodecs: GenCodec[?]*): GenCodec[T] = ??? - implicit def tuple2Codec[T1, T2](implicit r1: GenCodec[T1], r2: GenCodec[T2]): GenCodec[(T1, T2)] = + given tuple2Codec[T1, T2](using r1: GenCodec[T1], r2: GenCodec[T2]): GenCodec[(T1, T2)] = mkTupleCodec(r1, r2) - implicit def tuple3Codec[T1, T2, T3](implicit r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3]) - : GenCodec[(T1, T2, T3)] = + given tuple3Codec[T1, T2, T3](using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3]): GenCodec[(T1, T2, T3)] = mkTupleCodec(r1, r2, r3) - implicit def tuple4Codec[T1, T2, T3, T4]( - implicit r1: GenCodec[T1], + given tuple4Codec[T1, T2, T3, T4]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], ): GenCodec[(T1, T2, T3, T4)] = mkTupleCodec(r1, r2, r3, r4) - implicit def tuple5Codec[T1, T2, T3, T4, T5]( - implicit r1: GenCodec[T1], + given tuple5Codec[T1, T2, T3, T4, T5]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -29,8 +28,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5)] = mkTupleCodec(r1, r2, r3, r4, r5) - implicit def tuple6Codec[T1, T2, T3, T4, T5, T6]( - implicit r1: GenCodec[T1], + given tuple6Codec[T1, T2, T3, T4, T5, T6]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -39,8 +38,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6)] = mkTupleCodec(r1, r2, r3, r4, r5, r6) - implicit def tuple7Codec[T1, T2, T3, T4, T5, T6, T7]( - implicit r1: GenCodec[T1], + given tuple7Codec[T1, T2, T3, T4, T5, T6, T7]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -50,8 +49,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7) - implicit def tuple8Codec[T1, T2, T3, T4, T5, T6, T7, T8]( - implicit r1: GenCodec[T1], + given tuple8Codec[T1, T2, T3, T4, T5, T6, T7, T8]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -62,8 +61,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8) - implicit def tuple9Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9]( - implicit r1: GenCodec[T1], + given tuple9Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -75,8 +74,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9) - implicit def tuple10Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]( - implicit r1: GenCodec[T1], + given tuple10Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -89,8 +88,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10) - implicit def tuple11Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]( - implicit r1: GenCodec[T1], + given tuple11Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -104,8 +103,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11) - implicit def tuple12Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]( - implicit r1: GenCodec[T1], + given tuple12Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -120,8 +119,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12) - implicit def tuple13Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]( - implicit r1: GenCodec[T1], + given tuple13Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -137,8 +136,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13) - implicit def tuple14Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]( - implicit r1: GenCodec[T1], + given tuple14Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -155,8 +154,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14) - implicit def tuple15Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]( - implicit r1: GenCodec[T1], + given tuple15Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -174,8 +173,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15) - implicit def tuple16Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]( - implicit r1: GenCodec[T1], + given tuple16Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -194,8 +193,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16) - implicit def tuple17Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]( - implicit r1: GenCodec[T1], + given tuple17Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -215,8 +214,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17) - implicit def tuple18Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]( - implicit r1: GenCodec[T1], + given tuple18Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -237,8 +236,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17, r18) - implicit def tuple19Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]( - implicit r1: GenCodec[T1], + given tuple19Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -260,8 +259,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17, r18, r19) - implicit def tuple20Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]( - implicit r1: GenCodec[T1], + given tuple20Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -284,30 +283,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17, r18, r19, r20) - implicit def tuple21Codec[ - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - ](implicit - r1: GenCodec[T1], + given tuple21Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -331,31 +308,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17, r18, r19, r20, r21) - implicit def tuple22Codec[ - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - ](implicit - r1: GenCodec[T1], + given tuple22Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], diff --git a/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborAdtMetadata.scala b/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborAdtMetadata.scala index b29a238de..962525afd 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborAdtMetadata.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborAdtMetadata.scala @@ -17,7 +17,7 @@ import scala.annotation.nowarn * map keys can be of arbitrary type and not just strings */ abstract class HasCborCodec[T](implicit instances: MacroInstances[CborOptimizedCodecs, CborAdtInstances[T]]) { - implicit lazy val codec: GenObjectCodec[T] = instances(CborOptimizedCodecs, this).cborCodec + given codec: GenObjectCodec[T] = instances(CborOptimizedCodecs, this).cborCodec } /** Like [[HasCborCodec]] but allows injecting additional implicits - like [[HasGenCodecWithDeps]]. @@ -33,7 +33,7 @@ abstract class HasCborCodecWithDeps[D, T]( instances: MacroInstances[(CborOptimizedCodecs, D), CborAdtInstances[T]], ) = this()(using instances, applyUnapplyProvider.toScala) - implicit lazy val codec: GenObjectCodec[T] = instances((CborOptimizedCodecs, deps.value), this).cborCodec + given codec: GenObjectCodec[T] = instances((CborOptimizedCodecs, deps.value), this).cborCodec } /** Apply this annotation on a sealed trait/class whose companion extends [[HasCborCodec]] in order to customize the @@ -267,6 +267,6 @@ abstract class HasPolyCborCodec[C[_]]( ) { private lazy val validatedInstances = instances(CborOptimizedCodecs, this).setup(_.metadata[Nothing].validate()) - implicit def codec[T: GenCodec]: GenObjectCodec[C[T]] = + given codec[T: GenCodec]: GenObjectCodec[C[T]] = validatedInstances.metadata[T].adjustCodec(validatedInstances.stdCodec[T]) } diff --git a/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborOptimizedCodecs.scala b/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborOptimizedCodecs.scala index e0deb42e2..87b3b0dac 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborOptimizedCodecs.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborOptimizedCodecs.scala @@ -18,17 +18,22 @@ trait CborOptimizedCodecs { * serialization. If the key type has a `GenKeyCodec` then this `GenCodec` behaves exactly the same as the standard * one for non-CBOR inputs/outputs. */ - implicit def cborMapCodec[M[X, Y] <: BMap[X, Y], K: GenCodec: OptGenKeyCodec, V: GenCodec]( - implicit fac: Factory[(K, V), M[K, V]] - ): GenObjectCodec[M[K, V]] = mkMapCodec(implicit keyCodec => GenCodec.mapCodec[M, K, V]) + given cborMapCodec[M[X, Y] <: BMap[X, Y], K: GenCodec: OptGenKeyCodec, V: GenCodec](using fac: Factory[(K, V), M[K, V]]) + : GenObjectCodec[M[K, V]] = mkMapCodec { keyCodec => + given GenKeyCodec[K] = keyCodec + GenCodec.mapCodec[M, K, V] + } - implicit def cborJMapCodec[M[X, Y] <: JMap[X, Y], K: GenCodec: OptGenKeyCodec, V: GenCodec]( - implicit fac: JFactory[(K, V), M[K, V]] - ): GenObjectCodec[M[K, V]] = mkMapCodec(implicit keyCodec => GenCodec.jMapCodec[M, K, V]) + given cborJMapCodec[M[X, Y] <: JMap[X, Y], K: GenCodec: OptGenKeyCodec, V: GenCodec]( + using fac: JFactory[(K, V), M[K, V]] + ): GenObjectCodec[M[K, V]] = mkMapCodec { keyCodec => + given GenKeyCodec[K] = keyCodec + GenCodec.jMapCodec[M, K, V] + } private def mkMapCodec[M[X, Y] <: AnyRef, K: GenCodec: OptGenKeyCodec, V: GenCodec]( mkStdCodec: GenKeyCodec[K] => GenObjectCodec[M[K, V]] - )(implicit fac: Factory[(K, V), M[K, V]] + )(using fac: Factory[(K, V), M[K, V]] ): GenObjectCodec[M[K, V]] = { val hexKeysStdCodec = mkStdCodec(new GenKeyCodec[K] { def read(key: String): K = CborInput.readRawCbor[K](RawCbor.fromHex(key)) @@ -97,10 +102,10 @@ class OOOFieldCborRawKeysCodec[T](stdObjectCodec: OOOFieldsObjectCodec[T], keyCo */ case class OptGenKeyCodec[K](keyCodec: Opt[GenKeyCodec[K]]) object OptGenKeyCodec extends OptGenKeyCodecLowPriority { - def apply[K](implicit optGenKeyCodec: OptGenKeyCodec[K]): OptGenKeyCodec[K] = optGenKeyCodec + def apply[K](using optGenKeyCodec: OptGenKeyCodec[K]): OptGenKeyCodec[K] = optGenKeyCodec - implicit def fromKeyCodec[K: GenKeyCodec]: OptGenKeyCodec[K] = OptGenKeyCodec(Opt(GenKeyCodec[K])) + given fromKeyCodec[K: GenKeyCodec]: OptGenKeyCodec[K] = OptGenKeyCodec(Opt(GenKeyCodec[K])) } trait OptGenKeyCodecLowPriority { this: OptGenKeyCodec.type => - implicit def noKeyCodec[K]: OptGenKeyCodec[K] = OptGenKeyCodec(Opt.Empty) + given noKeyCodec[K]: OptGenKeyCodec[K] = OptGenKeyCodec(Opt.Empty) } diff --git a/core/src/main/scala/com/avsystem/commons/serialization/cbor/RawCbor.scala b/core/src/main/scala/com/avsystem/commons/serialization/cbor/RawCbor.scala index 08f716755..d3165c040 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/cbor/RawCbor.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/cbor/RawCbor.scala @@ -64,7 +64,7 @@ object RawCbor extends TypeMarker[RawCbor] { ): RawCbor = RawCbor(CborOutput.write(value, keyCodec, sizePolicy)) - implicit val codec: GenCodec[RawCbor] = + given codec: GenCodec[RawCbor] = GenCodec.nonNull( input => input.readCustom(RawCbor).getOrElse(RawCbor(input.readSimple().readBinary())), (output, cbor) => diff --git a/core/src/main/scala/com/avsystem/commons/serialization/json/WrappedJson.scala b/core/src/main/scala/com/avsystem/commons/serialization/json/WrappedJson.scala index 6f97936f8..49bf9ec66 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/json/WrappedJson.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/json/WrappedJson.scala @@ -11,7 +11,7 @@ import com.avsystem.commons.serialization.GenCodec */ final case class WrappedJson(value: String) extends AnyVal with CaseMethods object WrappedJson { - implicit val codec: GenCodec[WrappedJson] = GenCodec.create( + given codec: GenCodec[WrappedJson] = GenCodec.create( in => WrappedJson(in.readCustom(RawJson).getOrElse(in.readSimple().readString())), (out, v) => if (!out.writeCustom(RawJson, v.value)) out.writeSimple().writeString(v.value), ) diff --git a/core/src/main/scala/com/avsystem/commons/tuples/TupleDerivation.scala b/core/src/main/scala/com/avsystem/commons/tuples/TupleDerivation.scala index cd61185a6..77111e129 100644 --- a/core/src/main/scala/com/avsystem/commons/tuples/TupleDerivation.scala +++ b/core/src/main/scala/com/avsystem/commons/tuples/TupleDerivation.scala @@ -7,21 +7,21 @@ package tuples trait TupleDerivation[C[_]] { case class ElementInstances[T, I](instances: I) object ElementInstances { - implicit def tuple1Instances[T1](implicit i1: C[T1]): ElementInstances[Tuple1[T1], Tuple1[C[T1]]] = + given tuple1Instances[T1](using i1: C[T1]): ElementInstances[Tuple1[T1], Tuple1[C[T1]]] = ElementInstances(Tuple1(i1)) - implicit def tuple2Instances[T1, T2](implicit i1: C[T1], i2: C[T2]): ElementInstances[(T1, T2), (C[T1], C[T2])] = + given tuple2Instances[T1, T2](using i1: C[T1], i2: C[T2]): ElementInstances[(T1, T2), (C[T1], C[T2])] = ElementInstances((i1, i2)) - implicit def tuple3Instances[T1, T2, T3](implicit i1: C[T1], i2: C[T2], i3: C[T3]) + given tuple3Instances[T1, T2, T3](using i1: C[T1], i2: C[T2], i3: C[T3]) : ElementInstances[(T1, T2, T3), (C[T1], C[T2], C[T3])] = ElementInstances((i1, i2, i3)) - implicit def tuple4Instances[T1, T2, T3, T4](implicit i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4]) + given tuple4Instances[T1, T2, T3, T4](using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4]) : ElementInstances[(T1, T2, T3, T4), (C[T1], C[T2], C[T3], C[T4])] = ElementInstances((i1, i2, i3, i4)) - implicit def tuple5Instances[T1, T2, T3, T4, T5](implicit i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], i5: C[T5]) + given tuple5Instances[T1, T2, T3, T4, T5](using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], i5: C[T5]) : ElementInstances[(T1, T2, T3, T4, T5), (C[T1], C[T2], C[T3], C[T4], C[T5])] = ElementInstances((i1, i2, i3, i4, i5)) - implicit def tuple6Instances[T1, T2, T3, T4, T5, T6]( - implicit i1: C[T1], + given tuple6Instances[T1, T2, T3, T4, T5, T6]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -29,8 +29,8 @@ trait TupleDerivation[C[_]] { i6: C[T6], ): ElementInstances[(T1, T2, T3, T4, T5, T6), (C[T1], C[T2], C[T3], C[T4], C[T5], C[T6])] = ElementInstances((i1, i2, i3, i4, i5, i6)) - implicit def tuple7Instances[T1, T2, T3, T4, T5, T6, T7]( - implicit i1: C[T1], + given tuple7Instances[T1, T2, T3, T4, T5, T6, T7]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -39,8 +39,8 @@ trait TupleDerivation[C[_]] { i7: C[T7], ): ElementInstances[(T1, T2, T3, T4, T5, T6, T7), (C[T1], C[T2], C[T3], C[T4], C[T5], C[T6], C[T7])] = ElementInstances((i1, i2, i3, i4, i5, i6, i7)) - implicit def tuple8Instances[T1, T2, T3, T4, T5, T6, T7, T8]( - implicit i1: C[T1], + given tuple8Instances[T1, T2, T3, T4, T5, T6, T7, T8]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -50,8 +50,8 @@ trait TupleDerivation[C[_]] { i8: C[T8], ): ElementInstances[(T1, T2, T3, T4, T5, T6, T7, T8), (C[T1], C[T2], C[T3], C[T4], C[T5], C[T6], C[T7], C[T8])] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8)) - implicit def tuple9Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9]( - implicit i1: C[T1], + given tuple9Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -65,8 +65,8 @@ trait TupleDerivation[C[_]] { (C[T1], C[T2], C[T3], C[T4], C[T5], C[T6], C[T7], C[T8], C[T9]), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9)) - implicit def tuple10Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]( - implicit i1: C[T1], + given tuple10Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -81,8 +81,8 @@ trait TupleDerivation[C[_]] { (C[T1], C[T2], C[T3], C[T4], C[T5], C[T6], C[T7], C[T8], C[T9], C[T10]), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10)) - implicit def tuple11Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]( - implicit i1: C[T1], + given tuple11Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -98,8 +98,8 @@ trait TupleDerivation[C[_]] { (C[T1], C[T2], C[T3], C[T4], C[T5], C[T6], C[T7], C[T8], C[T9], C[T10], C[T11]), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11)) - implicit def tuple12Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]( - implicit i1: C[T1], + given tuple12Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -116,8 +116,8 @@ trait TupleDerivation[C[_]] { (C[T1], C[T2], C[T3], C[T4], C[T5], C[T6], C[T7], C[T8], C[T9], C[T10], C[T11], C[T12]), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12)) - implicit def tuple13Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]( - implicit i1: C[T1], + given tuple13Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -135,8 +135,8 @@ trait TupleDerivation[C[_]] { (C[T1], C[T2], C[T3], C[T4], C[T5], C[T6], C[T7], C[T8], C[T9], C[T10], C[T11], C[T12], C[T13]), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13)) - implicit def tuple14Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]( - implicit i1: C[T1], + given tuple14Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -155,8 +155,8 @@ trait TupleDerivation[C[_]] { (C[T1], C[T2], C[T3], C[T4], C[T5], C[T6], C[T7], C[T8], C[T9], C[T10], C[T11], C[T12], C[T13], C[T14]), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14)) - implicit def tuple15Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]( - implicit i1: C[T1], + given tuple15Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -176,8 +176,8 @@ trait TupleDerivation[C[_]] { (C[T1], C[T2], C[T3], C[T4], C[T5], C[T6], C[T7], C[T8], C[T9], C[T10], C[T11], C[T12], C[T13], C[T14], C[T15]), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15)) - implicit def tuple16Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]( - implicit i1: C[T1], + given tuple16Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -215,8 +215,8 @@ trait TupleDerivation[C[_]] { ), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16)) - implicit def tuple17Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]( - implicit i1: C[T1], + given tuple17Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -256,8 +256,8 @@ trait TupleDerivation[C[_]] { ), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16, i17)) - implicit def tuple18Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]( - implicit i1: C[T1], + given tuple18Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -299,8 +299,8 @@ trait TupleDerivation[C[_]] { ), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16, i17, i18)) - implicit def tuple19Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]( - implicit i1: C[T1], + given tuple19Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -344,29 +344,8 @@ trait TupleDerivation[C[_]] { ), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16, i17, i18, i19)) - implicit def tuple20Instances[ - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - ](implicit - i1: C[T1], + given tuple20Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -412,7 +391,7 @@ trait TupleDerivation[C[_]] { ), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16, i17, i18, i19, i20)) - implicit def tuple21Instances[ + given tuple21Instances[ T1, T2, T3, @@ -434,7 +413,7 @@ trait TupleDerivation[C[_]] { T19, T20, T21, - ](implicit + ](using i1: C[T1], i2: C[T2], i3: C[T3], @@ -483,7 +462,7 @@ trait TupleDerivation[C[_]] { ), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16, i17, i18, i19, i20, i21)) - implicit def tuple22Instances[ + given tuple22Instances[ T1, T2, T3, @@ -506,7 +485,7 @@ trait TupleDerivation[C[_]] { T20, T21, T22, - ](implicit + ](using i1: C[T1], i2: C[T2], i3: C[T3], @@ -569,7 +548,7 @@ object GenTupleDerivation { val instParams = js.map(j => s"i$j: C[T$j]").mkString(",") val instTypes = js.map(j => s"C[T$j]").mkString(",") val instances = js.map(j => s"i$j").mkString(",") - println(s"def tuple${i}Instances[$tuple](implicit $instParams): ElementInstances[($tuple),($instTypes)] =\nElementInstances(($instances))") + println(s"def tuple${i}Instances[$tuple](using $instParams): ElementInstances[($tuple),($instTypes)] =\nElementInstances(($instances))") } } } diff --git a/hocon/src/main/scala/com/avsystem/commons/hocon/ConfigCompanion.scala b/hocon/src/main/scala/com/avsystem/commons/hocon/ConfigCompanion.scala index 99ac75f59..3211e33a3 100644 --- a/hocon/src/main/scala/com/avsystem/commons/hocon/ConfigCompanion.scala +++ b/hocon/src/main/scala/com/avsystem/commons/hocon/ConfigCompanion.scala @@ -11,16 +11,16 @@ import scala.concurrent.duration.* import scala.jdk.javaapi.DurationConverters trait HoconGenCodecs { - implicit def configCodec: GenCodec[Config] = HoconGenCodecs.ConfigCodec - implicit def finiteDurationCodec: GenCodec[FiniteDuration] = HoconGenCodecs.FiniteDurationCodec - implicit def jDurationCodec: GenCodec[JDuration] = HoconGenCodecs.JavaDurationCodec - implicit def periodCodec: GenCodec[Period] = HoconGenCodecs.PeriodCodec - implicit def sizeInBytesCodec: GenCodec[SizeInBytes] = HoconGenCodecs.SizeInBytesCodec - implicit def classKeyCodec: GenKeyCodec[Class[?]] = HoconGenCodecs.ClassKeyCodec - implicit def classCodec: GenCodec[Class[?]] = HoconGenCodecs.ClassCodec + given configCodec: GenCodec[Config] = HoconGenCodecs.ConfigCodec + given finiteDurationCodec: GenCodec[FiniteDuration] = HoconGenCodecs.FiniteDurationCodec + given jDurationCodec: GenCodec[JDuration] = HoconGenCodecs.JavaDurationCodec + given periodCodec: GenCodec[Period] = HoconGenCodecs.PeriodCodec + given sizeInBytesCodec: GenCodec[SizeInBytes] = HoconGenCodecs.SizeInBytesCodec + given classKeyCodec: GenKeyCodec[Class[?]] = HoconGenCodecs.ClassKeyCodec + given classCodec: GenCodec[Class[?]] = HoconGenCodecs.ClassCodec } object HoconGenCodecs { - implicit final val ConfigCodec: GenCodec[Config] = GenCodec.nullable( + given ConfigCodec: GenCodec[Config] = GenCodec.nullable( input => input.readCustom(ConfigValueMarker).fold(ConfigFactory.parseString(input.readSimple().readString())) { case obj: ConfigObject => obj.toConfig @@ -33,7 +33,7 @@ object HoconGenCodecs { }, ) - implicit final val FiniteDurationCodec: GenCodec[FiniteDuration] = GenCodec.nullable( + given FiniteDurationCodec: GenCodec[FiniteDuration] = GenCodec.nullable( input => input.readCustom(DurationMarker).map(DurationConverters.toScala).getOrElse(input.readSimple().readLong().millis), (output, value) => @@ -41,26 +41,26 @@ object HoconGenCodecs { output.writeSimple().writeLong(value.toMillis), ) - implicit final val JavaDurationCodec: GenCodec[JDuration] = GenCodec.nullable( + given JavaDurationCodec: GenCodec[JDuration] = GenCodec.nullable( input => input.readCustom(DurationMarker).getOrElse(JDuration.ofMillis(input.readSimple().readLong())), (output, value) => if (!output.writeCustom(DurationMarker, value)) output.writeSimple().writeLong(value.toMillis), ) - implicit final val PeriodCodec: GenCodec[Period] = GenCodec.nullable( + given PeriodCodec: GenCodec[Period] = GenCodec.nullable( input => input.readCustom(PeriodMarker).getOrElse(Period.parse(input.readSimple().readString())), (output, value) => if (!output.writeCustom(PeriodMarker, value)) output.writeSimple().writeString(value.toString), ) - implicit final val SizeInBytesCodec: GenCodec[SizeInBytes] = GenCodec.nonNull( + given SizeInBytesCodec: GenCodec[SizeInBytes] = GenCodec.nonNull( input => SizeInBytes(input.readCustom(SizeInBytesMarker).getOrElse(input.readSimple().readLong())), (output, value) => if (!output.writeCustom(SizeInBytesMarker, value.bytes)) output.writeSimple().writeLong(value.bytes), ) - implicit final val ClassKeyCodec: GenKeyCodec[Class[?]] = + given ClassKeyCodec: GenKeyCodec[Class[?]] = GenKeyCodec.create(Class.forName, _.getName) - implicit final val ClassCodec: GenCodec[Class[?]] = + given ClassCodec: GenCodec[Class[?]] = GenCodec.nullableString(Class.forName, _.getName) } @@ -72,9 +72,9 @@ trait ConfigObjectCodec[T] { abstract class AbstractConfigCompanion[Implicits <: HoconGenCodecs, T]( implicits: Implicits -)(implicit instances: MacroInstances[Implicits, ConfigObjectCodec[T]] +)(using instances: MacroInstances[Implicits, ConfigObjectCodec[T]] ) { - implicit lazy val codec: GenCodec[T] = instances(implicits, this).objectCodec + given codec: GenCodec[T] = instances(implicits, this).objectCodec final def read(config: Config): T = HoconInput.read[T](config) } @@ -86,5 +86,5 @@ abstract class AbstractConfigCompanion[Implicits <: HoconGenCodecs, T]( * that it automatically imports codecs from [[HoconGenCodecs]] - codecs for third party types often used in * configuration. */ -abstract class DefaultConfigCompanion[T](implicit macroCodec: MacroInstances[HoconGenCodecs, ConfigObjectCodec[T]]) +abstract class DefaultConfigCompanion[T](using macroCodec: MacroInstances[HoconGenCodecs, ConfigObjectCodec[T]]) extends AbstractConfigCompanion[HoconGenCodecs, T](DefaultHoconGenCodecs) diff --git a/hocon/src/main/scala/com/avsystem/commons/hocon/HTree.scala b/hocon/src/main/scala/com/avsystem/commons/hocon/HTree.scala index 16ec7d191..f3c6327e5 100644 --- a/hocon/src/main/scala/com/avsystem/commons/hocon/HTree.scala +++ b/hocon/src/main/scala/com/avsystem/commons/hocon/HTree.scala @@ -56,12 +56,12 @@ object HTree { final case class HQualifiedInclude(qualifier: HIncludeQualifier, target: HString)(val tokens: HTokenRange) extends HRegularIncludeTarget - final class HIncludeQualifier(implicit enumCtx: EnumCtx) extends AbstractValueEnum + final class HIncludeQualifier(using enumCtx: EnumCtx) extends AbstractValueEnum object HIncludeQualifier extends AbstractValueEnumCompanion[HIncludeQualifier] { final val Classpath, File, Url: Value = new HIncludeQualifier } - final class HStringSyntax(implicit enumCtx: EnumCtx) extends AbstractValueEnum + final class HStringSyntax(using enumCtx: EnumCtx) extends AbstractValueEnum object HStringSyntax extends AbstractValueEnumCompanion[HStringSyntax] { final val Whitespace, Unquoted, Quoted, Multiline: Value = new HStringSyntax } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonCodec.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonCodec.scala index 85e0b0ea4..978e00934 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonCodec.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonCodec.scala @@ -22,7 +22,7 @@ trait BsonCodec[A, BSON <: BsonValue] { self => def key(key: String): DocKey[A, BSON] = new DocKey[A, BSON](key, this) - def collection[C[X] <: IterableOnce[X]](implicit fac: Factory[A, C[A]]): BsonCodec[C[A], BsonArray] = + def collection[C[X] <: IterableOnce[X]](using fac: Factory[A, C[A]]): BsonCodec[C[A], BsonArray] = BsonCodec.create[C[A], BsonArray]( ba => ba.iterator().asScala.map(bv => self.fromBson(bv.asInstanceOf[BSON])).to(fac), col => new BsonArray(col.iterator.map(self.toBson).to(JList)), diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonGenCodecs.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonGenCodecs.scala index 57291ea71..d2a1ea9b7 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonGenCodecs.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonGenCodecs.scala @@ -10,46 +10,28 @@ import org.bson.types.{Decimal128, ObjectId} import java.nio.ByteBuffer trait BsonGenCodecs { - implicit def objectIdIdentityWrapping: TransparentWrapping[ObjectId, ObjectId] = - BsonGenCodecs.objectIdIdentityWrapping - implicit def objectIdCodec: GenCodec[ObjectId] = BsonGenCodecs.objectIdCodec - implicit def objectIdKeyCodec: GenKeyCodec[ObjectId] = BsonGenCodecs.objectIdKeyCodec - implicit def decimal128Codec: GenCodec[Decimal128] = BsonGenCodecs.decimal128Codec - - implicit def bsonArrayCodec: GenCodec[BsonArray] = BsonGenCodecs.bsonArrayCodec - implicit def bsonBinaryCodec: GenCodec[BsonBinary] = BsonGenCodecs.bsonBinaryCodec - implicit def bsonBooleanCodec: GenCodec[BsonBoolean] = BsonGenCodecs.bsonBooleanCodec - implicit def bsonDateTimeCodec: GenCodec[BsonDateTime] = BsonGenCodecs.bsonDateTimeCodec - implicit def bsonDocumentCodec: GenCodec[BsonDocument] = BsonGenCodecs.bsonDocumentCodec - implicit def bsonDecimal128Codec: GenCodec[BsonDecimal128] = BsonGenCodecs.bsonDecimal128Codec - implicit def bsonDoubleCodec: GenCodec[BsonDouble] = BsonGenCodecs.bsonDoubleCodec - implicit def bsonInt32Codec: GenCodec[BsonInt32] = BsonGenCodecs.bsonInt32Codec - implicit def bsonInt64Codec: GenCodec[BsonInt64] = BsonGenCodecs.bsonInt64Codec - implicit def bsonNullCodec: GenCodec[BsonNull] = BsonGenCodecs.bsonNullCodec - implicit def bsonObjectIdCodec: GenCodec[BsonObjectId] = BsonGenCodecs.bsonObjectIdCodec - implicit def bsonStringCodec: GenCodec[BsonString] = BsonGenCodecs.bsonStringCodec - implicit def bsonValueCodec: GenCodec[BsonValue] = BsonGenCodecs.bsonValueCodec + export BsonGenCodecs.given } object BsonGenCodecs { // needed so that ObjectId can be used as ID type in AutoIdMongoEntity // (TransparentWrapping is used in EntityIdMode) - implicit val objectIdIdentityWrapping: TransparentWrapping[ObjectId, ObjectId] = TransparentWrapping.identity + given objectIdIdentityWrapping: TransparentWrapping[ObjectId, ObjectId] = TransparentWrapping.identity - implicit val objectIdCodec: GenCodec[ObjectId] = GenCodec.nullable( + given objectIdCodec: GenCodec[ObjectId] = GenCodec.nullable( i => i.readCustom(ObjectIdMarker).getOrElse(new ObjectId(i.readSimple().readString())), (o, v) => if (!o.writeCustom(ObjectIdMarker, v)) o.writeSimple().writeString(v.toHexString), ) - implicit val objectIdKeyCodec: GenKeyCodec[ObjectId] = + given objectIdKeyCodec: GenKeyCodec[ObjectId] = GenKeyCodec.create(new ObjectId(_), _.toHexString) - implicit val decimal128Codec: GenCodec[Decimal128] = GenCodec.nullable( + given decimal128Codec: GenCodec[Decimal128] = GenCodec.nullable( i => i.readCustom(Decimal128Marker).getOrElse(new Decimal128(i.readSimple().readBigDecimal().bigDecimal)), (o, v) => if (!o.writeCustom(Decimal128Marker, v)) o.writeSimple().writeBigDecimal(v.bigDecimalValue()), ) - implicit val bsonValueCodec: GenCodec[BsonValue] = GenCodec.create( + given bsonValueCodec: GenCodec[BsonValue] = GenCodec.create( i => i.readCustom(BsonValueMarker).getOrElse { val reader = new BsonBinaryReader(ByteBuffer.wrap(i.readSimple().readBinary())) @@ -67,27 +49,27 @@ object BsonGenCodecs { ) private def bsonValueSubCodec[T <: BsonValue](fromBsonValue: BsonValue => T): GenCodec[T] = - bsonValueCodec.transform(identity, fromBsonValue) + summon[GenCodec[BsonValue]].transform(identity, fromBsonValue) - implicit val bsonArrayCodec: GenCodec[BsonArray] = bsonValueSubCodec(_.asArray()) - implicit val bsonBinaryCodec: GenCodec[BsonBinary] = bsonValueSubCodec(_.asBinary()) - implicit val bsonBooleanCodec: GenCodec[BsonBoolean] = bsonValueSubCodec(_.asBoolean()) - implicit val bsonDateTimeCodec: GenCodec[BsonDateTime] = bsonValueSubCodec(_.asDateTime()) - implicit val bsonDocumentCodec: GenCodec[BsonDocument] = bsonValueSubCodec(_.asDocument()) - implicit val bsonDecimal128Codec: GenCodec[BsonDecimal128] = bsonValueSubCodec(_.asDecimal128()) - implicit val bsonDoubleCodec: GenCodec[BsonDouble] = bsonValueSubCodec(_.asDouble()) - implicit val bsonInt32Codec: GenCodec[BsonInt32] = bsonValueSubCodec(_.asInt32()) - implicit val bsonInt64Codec: GenCodec[BsonInt64] = bsonValueSubCodec(_.asInt64()) + given bsonArrayCodec: GenCodec[BsonArray] = bsonValueSubCodec(_.asArray()) + given bsonBinaryCodec: GenCodec[BsonBinary] = bsonValueSubCodec(_.asBinary()) + given bsonBooleanCodec: GenCodec[BsonBoolean] = bsonValueSubCodec(_.asBoolean()) + given bsonDateTimeCodec: GenCodec[BsonDateTime] = bsonValueSubCodec(_.asDateTime()) + given bsonDocumentCodec: GenCodec[BsonDocument] = bsonValueSubCodec(_.asDocument()) + given bsonDecimal128Codec: GenCodec[BsonDecimal128] = bsonValueSubCodec(_.asDecimal128()) + given bsonDoubleCodec: GenCodec[BsonDouble] = bsonValueSubCodec(_.asDouble()) + given bsonInt32Codec: GenCodec[BsonInt32] = bsonValueSubCodec(_.asInt32()) + given bsonInt64Codec: GenCodec[BsonInt64] = bsonValueSubCodec(_.asInt64()) - implicit val bsonNullCodec: GenCodec[BsonNull] = + given bsonNullCodec: GenCodec[BsonNull] = bsonValueSubCodec { bv => if (bv.isNull) BsonNull.VALUE else throw new ReadFailure("Input did not contain expected null value") } - implicit val bsonObjectIdCodec: GenCodec[BsonObjectId] = - objectIdCodec.transform(_.getValue, new BsonObjectId(_)) + given bsonObjectIdCodec: GenCodec[BsonObjectId] = + summon[GenCodec[ObjectId]].transform(_.getValue, new BsonObjectId(_)) - implicit val bsonStringCodec: GenCodec[BsonString] = - GenCodec.StringCodec.transform(_.getValue, new BsonString(_)) + given bsonStringCodec: GenCodec[BsonString] = + summon[GenCodec[String]].transform(_.getValue, new BsonString(_)) } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonRef.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonRef.scala index 1b7df8873..185164c29 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonRef.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonRef.scala @@ -19,7 +19,7 @@ case class BsonRef[S, T](path: String, codec: GenCodec[T], getter: S => T) { object BsonRef { val BsonKeySeparator = "." - def identity[S](implicit codec: GenCodec[S]): BsonRef[S, S] = BsonRef("", codec, s => s) + def identity[S](using codec: GenCodec[S]): BsonRef[S, S] = BsonRef("", codec, s => s) def create[S]: Creator[S] = new Creator[S] {} trait Creator[S] { @@ -29,7 +29,7 @@ object BsonRef { def ref[T](fun: S => T): BsonRef[S, T] = ??? } - def apply[S, T](genRef: GenRef[S, T])(implicit codec: GenCodec[T]): BsonRef[S, T] = { + def apply[S, T](genRef: GenRef[S, T])(using codec: GenCodec[T]): BsonRef[S, T] = { val path = genRef.rawRef.normalize .map { case Field(name) => KeyEscaper.escape(name) diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/DocKey.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/DocKey.scala index 5b60bab9d..6019521ec 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/DocKey.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/DocKey.scala @@ -8,7 +8,7 @@ import org.bson.{BsonDocument, BsonValue} * MKej */ case class DocKey[A, BSON <: BsonValue](key: String, codec: BsonCodec[A, BSON]) { - def ++[B, BBSON <: BsonValue](other: DocKey[B, BBSON])(implicit ev: BSON <:< BsonDocument): DocKey[B, BBSON] = + def ++[B, BBSON <: BsonValue](other: DocKey[B, BBSON])(using ev: BSON <:< BsonDocument): DocKey[B, BBSON] = new DocKey(key + "." + other.key, other.codec) } object DocKey { diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/Filter.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/Filter.scala index 06e898383..830478650 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/Filter.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/Filter.scala @@ -48,17 +48,17 @@ object Filter { def elemMatch(key: DocKey[_, _ <: BsonArray], filter: Bson): Bson = F.elemMatch(key.key, filter) - def contains[A, COL <: Iterable[A]](key: DocKey[COL, _ <: BsonArray], value: A)(implicit fac: Factory[A, COL]): Bson = + def contains[A, COL <: Iterable[A]](key: DocKey[COL, _ <: BsonArray], value: A)(using fac: Factory[A, COL]): Bson = F.eq(key.key, key.codec.toBson((fac.newBuilder += value).result()).asScala.head) object Limitations { trait CanCompare[BSON <: BsonValue] object CanCompare { def create[BSON <: BsonValue]: CanCompare[BSON] = new CanCompare[BSON] {} - implicit val date: CanCompare[BsonDateTime] = create[BsonDateTime] - implicit val int32: CanCompare[BsonInt32] = create[BsonInt32] - implicit val int64: CanCompare[BsonInt64] = create[BsonInt64] - implicit val double: CanCompare[BsonDouble] = create[BsonDouble] + given CanCompare[BsonDateTime] = create[BsonDateTime] + given CanCompare[BsonInt32] = create[BsonInt32] + given CanCompare[BsonInt64] = create[BsonInt64] + given CanCompare[BsonDouble] = create[BsonDouble] } } } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/GenCodecProvider.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/GenCodecProvider.scala index 825a886eb..26c45c8bd 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/GenCodecProvider.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/GenCodecProvider.scala @@ -6,7 +6,7 @@ import com.avsystem.commons.serialization.GenCodec import org.bson.codecs.Codec import org.bson.codecs.configuration.{CodecProvider, CodecRegistry} -class GenCodecProvider[T: GenCodec](legacyOptionEncoding: Boolean)(implicit ct: ClassTag[T]) extends CodecProvider { +class GenCodecProvider[T: GenCodec](legacyOptionEncoding: Boolean)(using ct: ClassTag[T]) extends CodecProvider { private val mongoCodec = new GenCodecBasedBsonCodec[T](legacyOptionEncoding) private val runtimeClass = ct.runtimeClass diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefIterableFiltering.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefIterableFiltering.scala index cebf0bc24..b322205cd 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefIterableFiltering.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefIterableFiltering.scala @@ -6,7 +6,7 @@ import com.avsystem.commons.serialization.GenCodec final class BsonRefIterableFiltering[E, C[T] <: Iterable[T]]( protected val bsonRef: BsonRef[_, C[E]] -)(implicit protected val elementCodec: GenCodec[E] +)(using protected val elementCodec: GenCodec[E] ) extends BaseIterableFiltering[E, C] with BsonRefKeyValueHandling[C[E]] with BsonRefKeyElementHandling[E, C] diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefIterableUpdating.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefIterableUpdating.scala index 3ba04cbab..6a7312bd9 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefIterableUpdating.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefIterableUpdating.scala @@ -6,7 +6,7 @@ import com.avsystem.commons.serialization.GenCodec final class BsonRefIterableUpdating[E, C[T] <: Iterable[T]]( protected val bsonRef: BsonRef[_, C[E]] -)(implicit protected val elementCodec: GenCodec[E] +)(using protected val elementCodec: GenCodec[E] ) extends BaseIterableUpdating[E, C] with BsonRefKeyValueHandling[C[E]] with BsonRefKeyElementHandling[E, C] diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefKeyElementHandling.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefKeyElementHandling.scala index d86cfbab5..8ba4dd057 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefKeyElementHandling.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefKeyElementHandling.scala @@ -6,7 +6,7 @@ import com.avsystem.commons.serialization.GenCodec import org.bson.BsonValue trait BsonRefKeyElementHandling[E, C[T] <: Iterable[T]] extends KeyElementHandling[E] with BsonRefKeyHandling[C[E]] { - protected implicit def elementCodec: GenCodec[E] + protected given elementCodec: GenCodec[E] override protected def encodeElement(e: E): BsonValue = BsonValueOutput.write(e) } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/KeyGetter.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/KeyGetter.scala index 41c7dd72e..ad4116d44 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/KeyGetter.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/KeyGetter.scala @@ -8,11 +8,11 @@ trait KeyGetter[-T] { } object KeyGetter { - implicit object bsonRefKeyGetter extends KeyGetter[BsonRef[_, _]] { + given bsonRefKeyGetter: KeyGetter[BsonRef[_, _]] with { override def keyOf(t: BsonRef[_, _]): String = t.path } - implicit object docKeyKeyGetter extends KeyGetter[DocKey[_, _]] { + given docKeyKeyGetter: KeyGetter[DocKey[_, _]] with { override def keyOf(t: DocKey[_, _]): String = t.key } } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/Sorting.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/Sorting.scala index 799ffb678..c5588c021 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/Sorting.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/Sorting.scala @@ -5,8 +5,8 @@ import com.mongodb.client.model.Sorts import org.bson.conversions.Bson object Sorting { - def ascending[K](keys: K*)(implicit kg: KeyGetter[K]): Bson = Sorts.ascending(keys.map(kg.keyOf).asJava) - def descending[K](keys: K*)(implicit kg: KeyGetter[K]): Bson = Sorts.descending(keys.map(kg.keyOf).asJava) + def ascending[K](keys: K*)(using kg: KeyGetter[K]): Bson = Sorts.ascending(keys.map(kg.keyOf).asJava) + def descending[K](keys: K*)(using kg: KeyGetter[K]): Bson = Sorts.descending(keys.map(kg.keyOf).asJava) def orderBy(sorts: Bson*): Bson = Sorts.orderBy(sorts.asJava) } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/sync/MongoOps.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/sync/MongoOps.scala index 67e101429..b7489c313 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/sync/MongoOps.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/sync/MongoOps.scala @@ -20,8 +20,7 @@ trait MongoOps { object MongoOps { final class DBOps(private val db: MongoDatabase) extends AnyVal { - def getCollection[A](name: String, codec: BsonCodec[A, BsonDocument])(implicit ct: ClassTag[A]) - : MongoCollection[A] = { + def getCollection[A](name: String, codec: BsonCodec[A, BsonDocument])(using ct: ClassTag[A]): MongoCollection[A] = { val mongoCodec = new MongoCodec[A, BsonDocument](codec, db.getCodecRegistry) val registry = CodecRegistries.fromRegistries( CodecRegistries.fromCodecs(mongoCodec), diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/text/TextSearchLanguage.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/text/TextSearchLanguage.scala index 8b7f5f2ac..b8d0ecf15 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/text/TextSearchLanguage.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/text/TextSearchLanguage.scala @@ -10,7 +10,7 @@ import com.avsystem.commons.misc.{AbstractValueEnum, AbstractValueEnumCompanion, * @see * [[https://docs.mongodb.com/manual/reference/text-search-languages/#text-search-languages]] */ -final class TextSearchLanguage(val code: String)(implicit enumCtx: EnumCtx) extends AbstractValueEnum +final class TextSearchLanguage(val code: String)(using enumCtx: EnumCtx) extends AbstractValueEnum object TextSearchLanguage extends AbstractValueEnumCompanion[TextSearchLanguage] { /** Uses simple tokenization with no list of stop words and no stemming. diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/DataTypeDsl.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/DataTypeDsl.scala index e9ca5ce0c..48f00f4ba 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/DataTypeDsl.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/DataTypeDsl.scala @@ -14,7 +14,7 @@ trait DataRefDsl[E, T] { def SelfRef: ThisRef[E, T] // called by .ref macro to ensure that the source type is not opaque and inner references are possible - @macroPrivate def asAdtRef(implicit ev: IsMongoAdtOrSubtype[T]): ThisRef[E, T] = SelfRef + @macroPrivate def asAdtRef(using ev: IsMongoAdtOrSubtype[T]): ThisRef[E, T] = SelfRef /** A macro that interprets an anonymous function as a [[MongoPropertyRef]]. * diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala index e104a5424..fbf0fa11e 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala @@ -2,6 +2,7 @@ package com.avsystem.commons package mongo.typed import com.avsystem.commons.mongo.{mongoId, BsonGenCodecs} +import com.avsystem.commons.mongo.BsonGenCodecs.given import com.avsystem.commons.serialization.{GenCodec, TransparentWrapping} import org.bson.types.ObjectId @@ -20,7 +21,7 @@ sealed trait EntityIdMode[E, ID] { case EntityIdMode.Explicit() => format.fieldRefFor(MongoRef.RootRef(format), MongoEntity.Id) case EntityIdMode.Auto(idWrapping) => - val idCodec = GenCodec.fromTransparentWrapping(idWrapping, BsonGenCodecs.objectIdCodec) + val idCodec = GenCodec.fromTransparentWrapping(using idWrapping)(using summon[GenCodec[ObjectId]]) MongoRef.FieldRef(MongoRef.RootRef(format), mongoId.Id, MongoFormat.Opaque(idCodec), Opt.Empty) } } @@ -28,9 +29,8 @@ object EntityIdMode { case class Explicit[E, ID]() extends EntityIdMode[E, ID] case class Auto[E, ID](idWrapping: TransparentWrapping[ObjectId, ID]) extends EntityIdMode[E, ID] - implicit def explicitIdMode[E <: MongoEntity[ID], ID]: EntityIdMode[E, ID] = Explicit() + given explicitIdMode[E <: MongoEntity[ID], ID]: EntityIdMode[E, ID] = Explicit() - implicit def autoIdMode[E <: AutoIdMongoEntity[ID], ID]( - implicit idWrapping: TransparentWrapping[ObjectId, ID] - ): EntityIdMode[E, ID] = Auto(idWrapping) + given autoIdMode[E <: AutoIdMongoEntity[ID], ID](using idWrapping: TransparentWrapping[ObjectId, ID]) + : EntityIdMode[E, ID] = Auto(idWrapping) } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoEntityCompanion.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoEntityCompanion.scala index f59d9f430..e481721cb 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoEntityCompanion.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoEntityCompanion.scala @@ -24,10 +24,10 @@ trait MongoEntityInstances[E <: BaseMongoEntity] extends MongoAdtInstances[E] { sealed trait IsMongoAdtOrSubtype[T] sealed abstract class BaseMongoCompanion[T] extends DataTypeDsl[T] { - implicit def codec: GenObjectCodec[T] - implicit def format: MongoAdtFormat[T] + given codec: GenObjectCodec[T] + given format: MongoAdtFormat[T] - implicit def isMongoAdtOrSubtype[C <: T]: IsMongoAdtOrSubtype[C] = null + given isMongoAdtOrSubtype[C <: T]: IsMongoAdtOrSubtype[C] = null implicit class macroDslExtensions(value: T) { @explicitGenerics @@ -40,19 +40,19 @@ sealed abstract class BaseMongoCompanion[T] extends DataTypeDsl[T] { abstract class AbstractMongoDataCompanion[Implicits, E]( implicits: Implicits -)(implicit instances: MacroInstances[Implicits, MongoAdtInstances[E]] +)(using instances: MacroInstances[Implicits, MongoAdtInstances[E]] ) extends BaseMongoCompanion[E] { - implicit val codec: GenObjectCodec[E] = instances(implicits, this).codec - implicit val format: MongoAdtFormat[E] = instances(implicits, this).format + given codec: GenObjectCodec[E] = instances(implicits, this).codec + given format: MongoAdtFormat[E] = instances(implicits, this).format } abstract class AbstractMongoEntityCompanion[Implicits, E <: BaseMongoEntity]( implicits: Implicits -)(implicit instances: MacroInstances[Implicits, MongoEntityInstances[E]] +)(using instances: MacroInstances[Implicits, MongoEntityInstances[E]] ) extends BaseMongoCompanion[E] { - implicit val codec: GenObjectCodec[E] = instances(implicits, this).codec - implicit val format: MongoAdtFormat[E] = instances(implicits, this).format - implicit val meta: MongoEntityMeta[E] = instances(implicits, this).meta + given codec: GenObjectCodec[E] = instances(implicits, this).codec + given format: MongoAdtFormat[E] = instances(implicits, this).format + given meta: MongoEntityMeta[E] = instances(implicits, this).meta // TODO[scala3-port]: `E#IDType` type projection forbidden on abstract types; widen to Any to keep signatures (M) type ID = Any diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoFormat.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoFormat.scala index 97b9c499f..cc36aa229 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoFormat.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoFormat.scala @@ -14,7 +14,7 @@ import scala.annotation.tailrec * indirectly as an embedded value). */ sealed trait MongoFormat[T] { - implicit def codec: GenCodec[T] + given codec: GenCodec[T] def writeBson(value: T): BsonValue = BsonValueOutput.write(value) @@ -93,35 +93,31 @@ object MongoFormat extends MetadataCompanion[MongoFormat] with MongoFormatLowPri wrappedFormat: MongoFormat[R], ) extends MongoFormat[T] - implicit def collectionFormat[C[X] <: Iterable[X], T]( - implicit collectionCodec: GenCodec[C[T]], - elementFormat: MongoFormat[T], - ): MongoFormat[C[T]] = CollectionFormat(collectionCodec, elementFormat) + given collectionFormat: [C[X] <: Iterable[X], T] => (collectionCodec: GenCodec[C[T]]) => (elementFormat: MongoFormat[T]) + => MongoFormat[C[T]] = CollectionFormat(collectionCodec, elementFormat) - implicit def dictionaryFormat[M[X, Y] <: BMap[X, Y], K, V]( - implicit mapCodec: GenCodec[M[K, V]], + given dictionaryFormat: [M[X, Y] <: BMap[X, Y], K, V] => ( + mapCodec: GenCodec[M[K, V]], keyCodec: GenKeyCodec[K], valueFormat: MongoFormat[V], - ): MongoFormat[M[K, V]] = DictionaryFormat(mapCodec, keyCodec, valueFormat) + ) => MongoFormat[M[K, V]] = DictionaryFormat(mapCodec, keyCodec, valueFormat) // TODO[scala3-port]: K[_] → K[Any] workaround for Scala 3 wildcard-as-type-arg restriction (S) - implicit def typedMapFormat[K[_]]( - implicit keyCodec: GenKeyCodec[K[Any]], - valueFormats: MongoFormatMapping[K], - ): MongoFormat[TypedMap[K]] = + given typedMapFormat: [K[_]] => (keyCodec: GenKeyCodec[K[Any]]) => (valueFormats: MongoFormatMapping[K]) + => MongoFormat[TypedMap[K]] = TypedMapFormat[K](TypedMap.typedMapCodec, keyCodec, valueFormats) - implicit def optionalFormat[O, T]( - implicit optionLike: OptionLike.Aux[O, T], + given optionalFormat: [O, T] => ( + optionLike: OptionLike.Aux[O, T], optionCodec: GenCodec[O], wrappedFormat: MongoFormat[T], - ): MongoFormat[O] = OptionalFormat(optionCodec, optionLike, wrappedFormat) + ) => MongoFormat[O] = OptionalFormat(optionCodec, optionLike, wrappedFormat) - implicit def transparentFormat[R, T]( - implicit codec: GenCodec[T], + given transparentFormat: [R, T] => ( + codec: GenCodec[T], wrapping: TransparentWrapping[R, T], wrappedFormat: MongoFormat[R], - ): MongoFormat[T] = TransparentFormat(codec, wrapping, wrappedFormat) + ) => MongoFormat[T] = TransparentFormat(codec, wrapping, wrappedFormat) implicit class collectionFormatOps[C[X] <: Iterable[X], T](private val format: MongoFormat[C[T]]) extends AnyVal { def assumeCollection: CollectionFormat[C, T] = format match { @@ -158,13 +154,13 @@ object MongoFormat extends MetadataCompanion[MongoFormat] with MongoFormatLowPri } } trait MongoFormatLowPriority { this: MongoFormat.type => - implicit def leafFormat[T: GenCodec]: MongoFormat[T] = Opaque(GenCodec[T]) + given leafFormat: [T: GenCodec] => MongoFormat[T] = Opaque(GenCodec[T]) } sealed trait MongoAdtFormat[T] extends MongoFormat[T] with TypedMetadata[T] { - implicit def codec: GenObjectCodec[T] + given codec: GenObjectCodec[T] // this is not named `classTag` in order to avoid naming conflict with `com.avsystem.commons.classTag` - implicit def dataClassTag: ClassTag[T] + given dataClassTag: ClassTag[T] def fieldRefFor[E, T0](prefix: MongoRef[E, T], scalaFieldName: String): MongoPropertyRef[E, T0] } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoIndex.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoIndex.scala index d2dc8cff3..b405c7616 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoIndex.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoIndex.scala @@ -67,7 +67,7 @@ object MongoIndex { MongoIndex(fields.iterator.map(f => f -> MongoIndexType.Descending).toVector) } -final class MongoIndexType(implicit enumCtx: EnumCtx) extends AbstractValueEnum { +final class MongoIndexType(using enumCtx: EnumCtx) extends AbstractValueEnum { import MongoIndexType._ diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoPolyDataCompanion.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoPolyDataCompanion.scala index 594ec7835..0b02ee904 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoPolyDataCompanion.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoPolyDataCompanion.scala @@ -21,17 +21,17 @@ trait MongoPolyAdtInstances[D[_]] { abstract class AbstractMongoPolyDataCompanion[Implicits, D[_]]( implicits: Implicits -)(implicit instances: MacroInstances[Implicits, MongoPolyAdtInstances[D]] +)(using instances: MacroInstances[Implicits, MongoPolyAdtInstances[D]] ) { - implicit def codec[T: GenCodec]: GenObjectCodec[D[T]] = instances(implicits, this).codec[T] + given codec[T: GenCodec]: GenObjectCodec[D[T]] = instances(implicits, this).codec[T] - implicit def format[T: MongoFormat]: MongoAdtFormat[D[T]] = { - implicit def tCodec: GenCodec[T] = MongoFormat[T].codec + given format[T: MongoFormat]: MongoAdtFormat[D[T]] = { + given tCodec: GenCodec[T] = MongoFormat[T].codec instances(implicits, this).format[T] } // TODO[scala3-port]: D[_] → D[Any] workaround for Scala 3 wildcard-as-type-arg restriction (S) - implicit def isMongoAdtOrSubtype[C <: D[Any]]: IsMongoAdtOrSubtype[C] = null + given isMongoAdtOrSubtype[C <: D[Any]]: IsMongoAdtOrSubtype[C] = null implicit class macroDslExtensions[T](value: D[T]) { @explicitGenerics diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoRef.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoRef.scala index 59926bf5d..cf7cbb693 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoRef.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoRef.scala @@ -279,7 +279,7 @@ object MongoPropertyRef { } } - implicit def optionalRefOps[E, O, T](ref: MongoPropertyRef[E, O])(implicit optionLike: OptionLike.Aux[O, T]) + implicit def optionalRefOps[E, O, T](ref: MongoPropertyRef[E, O])(using optionLike: OptionLike.Aux[O, T]) : OptionalRefOps[E, O, T] = new OptionalRefOps[E, O, T](ref) @@ -290,7 +290,7 @@ object MongoPropertyRef { } } - implicit def transparentRefOps[E, T, R](ref: MongoPropertyRef[E, T])(implicit wrapping: TransparentWrapping[R, T]) + implicit def transparentRefOps[E, T, R](ref: MongoPropertyRef[E, T])(using wrapping: TransparentWrapping[R, T]) : TransparentRefOps[E, T, R] = new TransparentRefOps[E, T, R](ref) diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoTypedKey.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoTypedKey.scala index 339a01ffa..924a92af2 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoTypedKey.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoTypedKey.scala @@ -15,7 +15,7 @@ trait MongoTypedKey[T] extends TypedKey[T] { override def valueCodec: GenCodec[T] = valueFormat.codec } object MongoTypedKey { - implicit def mongoFormatMapping[K[X] <: MongoTypedKey[X]]: MongoFormatMapping[K] = + given mongoFormatMapping[K[X] <: MongoTypedKey[X]]: MongoFormatMapping[K] = new MongoFormatMapping[K] { override def valueFormat[T](key: K[T]): MongoFormat[T] = key.valueFormat } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoUpdateOperator.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoUpdateOperator.scala index 0817d58cf..4d3a41b90 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoUpdateOperator.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoUpdateOperator.scala @@ -44,7 +44,7 @@ sealed trait MongoUpdateOperator[T] extends Product { } } object MongoUpdateOperator { - final class CurrentDateType(implicit enumCtx: EnumCtx) extends AbstractValueEnum + final class CurrentDateType(using enumCtx: EnumCtx) extends AbstractValueEnum object CurrentDateType extends AbstractValueEnumCompanion[CurrentDateType] { final val Timestamp, Date: Value = new CurrentDateType } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ObjectIdWrapperCompanion.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ObjectIdWrapperCompanion.scala index 2638cecff..9a05c5eea 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ObjectIdWrapperCompanion.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ObjectIdWrapperCompanion.scala @@ -2,6 +2,7 @@ package com.avsystem.commons package mongo.typed import com.avsystem.commons.mongo.BsonGenCodecs +import com.avsystem.commons.mongo.BsonGenCodecs.given import com.avsystem.commons.serialization.{GenCodec, TransparentWrapperCompanion} import org.bson.types.ObjectId @@ -23,5 +24,5 @@ abstract class ObjectIdWrapperCompanion[ID] extends TransparentWrapperCompanion[ */ def get(): ID = wrap(ObjectId.get()) - implicit val codec: GenCodec[ID] = GenCodec.fromTransparentWrapping(this, BsonGenCodecs.objectIdCodec) + given codec: GenCodec[ID] = GenCodec.fromTransparentWrapping(using this)(using summon[GenCodec[ObjectId]]) } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ProjectionZippers.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ProjectionZippers.scala index 379e50296..8cca8c727 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ProjectionZippers.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ProjectionZippers.scala @@ -357,7 +357,7 @@ trait ProjectionZippers { this: MongoProjection.type => ) } -final class ProductProjection[E, T](componentProjections: Seq[MongoProjection[E, _]])(implicit applier: Applier[T]) +final class ProductProjection[E, T](componentProjections: Seq[MongoProjection[E, _]])(using applier: Applier[T]) extends MongoProjection[E, T] { def projectionRefs: Set[MongoRef[E, _]] = diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/QueryOperatorsDsl.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/QueryOperatorsDsl.scala index ef7f2ae15..b70814157 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/QueryOperatorsDsl.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/QueryOperatorsDsl.scala @@ -101,7 +101,7 @@ object QueryOperatorsDsl { def containsAll(values: Iterable[T]): R = dsl.all(values) } - implicit def forOptional[O, T, R](dsl: QueryOperatorsDsl[O, R])(implicit optionLike: OptionLike.Aux[O, T]) + implicit def forOptional[O, T, R](dsl: QueryOperatorsDsl[O, R])(using optionLike: OptionLike.Aux[O, T]) : ForOptional[O, T, R] = new ForOptional(dsl) @@ -113,7 +113,7 @@ object QueryOperatorsDsl { } } -final class RegexFlag(val javaFlag: Int, val char: Char)(implicit enumCtx: EnumCtx) extends AbstractValueEnum +final class RegexFlag(val javaFlag: Int, val char: Char)(using enumCtx: EnumCtx) extends AbstractValueEnum object RegexFlag extends AbstractValueEnumCompanion[RegexFlag] { // code based on org.bson.codecs.PatternCodec diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/TypedMongoCollection.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/TypedMongoCollection.scala index df5e6c24a..cec156f45 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/TypedMongoCollection.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/TypedMongoCollection.scala @@ -19,14 +19,14 @@ class TypedMongoCollection[E <: BaseMongoEntity] private ( val nativeCollection: MongoCollection[E], docCollection: MongoCollection[BsonDocument], val clientSession: Opt[TypedClientSession], -)(implicit meta: MongoEntityMeta[E] +)(using meta: MongoEntityMeta[E] ) extends DataTypeDsl[E] with TypedMongoUtils { def this( rawCollection: MongoCollection[_], clientSession: OptArg[TypedClientSession] = OptArg.Empty, - )(implicit meta: MongoEntityMeta[E] + )(using meta: MongoEntityMeta[E] ) = this( TypedMongoCollection.mkNativeCollection[E](rawCollection), rawCollection.withDocumentClass(classOf[BsonDocument]), @@ -385,20 +385,20 @@ class TypedMongoCollection[E <: BaseMongoEntity] private ( } @bincompat private[typed] def this(rawCollection: MongoCollection[_], format: MongoAdtFormat[E]) = - this(rawCollection)(MongoEntityMeta.bincompatMeta(format)) + this(rawCollection)(using MongoEntityMeta.bincompatMeta(format)) @bincompat private[typed] def this(rawCollection: MongoCollection[_], meta: MongoEntityMeta[E]) = - this(rawCollection)(meta) + this(rawCollection)(using meta) } object TypedMongoCollection { private def mkNativeCollection[E <: BaseMongoEntity: MongoEntityMeta]( rawCollection: MongoCollection[_] - )(implicit meta: MongoEntityMeta[E] + )(using meta: MongoEntityMeta[E] ): MongoCollection[E] = { - import meta.format._ + import meta.format.{given, _} val codecRegistry: CodecRegistry = GenCodecRegistry.create[E](rawCollection.getCodecRegistry) - val documentClass = classTag.runtimeClass.asInstanceOf[Class[E]] + val documentClass = summon[ClassTag[E]].runtimeClass.asInstanceOf[Class[E]] rawCollection.withCodecRegistry(codecRegistry).withDocumentClass(documentClass) } }