Skip to content

Commit

Permalink
remove unused apply method from Castable, add codec to BaseOpaque
Browse files Browse the repository at this point in the history
  • Loading branch information
halotukozak committed Jul 16, 2024
1 parent b6a5b95 commit 392dc3c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package com.avsystem.commons
package opaque

import com.avsystem.commons.opaque.Castable.<:>
import com.avsystem.commons.serialization.GenCodec

private[opaque] trait BaseOpaque[From] extends Castable.Ops {
trait Tag
type Type

implicit protected final val castable: From <:> Type = new Castable[From, Type]

def apply(value: From): Type


implicit protected final val castable: From <:> Type = new Castable[From, Type]
implicit final def codec(implicit fromCodec: GenCodec[From]): GenCodec[Type] = wrapF(fromCodec)
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.avsystem.commons
package opaque

private[opaque] final class Castable[A, B] {
@inline def apply(a: A): B = a.asInstanceOf[B]
}
private[opaque] final class Castable[A, B]
private[opaque] object Castable {
type <:>[A, B] = Castable[A, B]
def apply[A, B](implicit ev: A <:> B): Castable[A, B] = ev
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package serialization
import com.avsystem.commons.annotation.AnnotationAggregate
import com.avsystem.commons.meta.{AutoOptionalParams, MacroInstances}
import com.avsystem.commons.misc.{AutoNamedEnum, NamedEnumCompanion, TypedKey}
import com.avsystem.commons.opaque.{Opaque, Subopaque}

import scala.annotation.meta.getter

Expand Down Expand Up @@ -134,6 +135,9 @@ object CodecTestData {
@transparent case class StringId(id: String)
object StringId extends TransparentWrapperCompanion[String, StringId]

object SomeOpaque extends Opaque.Default[Int]
object SomeSubopaque extends Subopaque.Default[Int]

trait HasSomeStr {
@name("some.str") def str: String
@generated def someStrLen: Int = str.length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ abstract class GenCodecRoundtripTest extends AbstractCodecTest {
testRoundtrip(StringId("lolfuu"), "lolfuu")
}

test("opaque and subopaque") {
testRoundtrip(SomeOpaque(42))
testRoundtrip(SomeSubopaque(42))
}

test("case class") {
testRoundtrip(SomeCaseClass("dafuq", List(1, 2, 3)))
}
Expand Down

0 comments on commit 392dc3c

Please sign in to comment.