Skip to content

Commit 4a8bf46

Browse files
committed
Introduce Encoder.of and Decoder.of, fixes #750
1 parent 7b819a2 commit 4a8bf46

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

Diff for: core/src/main/scala/io/bullet/borer/Decoder.scala

+7-9
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@ package io.bullet.borer
1111
import io.bullet.borer.encodings.BaseEncoding
1212
import io.bullet.borer.internal.Util
1313

14-
import java.lang.{
15-
Boolean as JBoolean,
16-
Byte as JByte,
17-
Double as JDouble,
18-
Float as JFloat,
19-
Long as JLong,
20-
Short as JShort
21-
}
14+
import java.lang.{Boolean as JBoolean, Byte as JByte, Double as JDouble, Float as JFloat, Long as JLong, Short as JShort}
2215
import java.math.{BigDecimal as JBigDecimal, BigInteger as JBigInteger}
2316
import scala.annotation.{nowarn, tailrec, threadUnsafe}
2417
import scala.collection.{mutable, Factory}
@@ -51,7 +44,12 @@ object Decoder extends LowPrioDecoders:
5144
/**
5245
* Creates a [[Decoder]] from the given function.
5346
*/
54-
inline def apply[T](implicit decoder: Decoder[T]): Decoder[T] = decoder
47+
inline def apply[T](decoder: Decoder[T]): Decoder[T] = decoder
48+
49+
/**
50+
* Gets a given [[Decoder]] for [[T]].
51+
*/
52+
inline def of[T: Decoder]: Decoder[T] = summon
5553

5654
/**
5755
* Creates a [[Decoder]] that decodes a product instance from a simple array of values.

Diff for: core/src/main/scala/io/bullet/borer/Encoder.scala

+7-9
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@ package io.bullet.borer
1111
import io.bullet.borer.encodings.BaseEncoding
1212
import io.bullet.borer.internal.{ElementDeque, Util}
1313

14-
import java.lang.{
15-
Boolean as JBoolean,
16-
Byte as JByte,
17-
Double as JDouble,
18-
Float as JFloat,
19-
Long as JLong,
20-
Short as JShort
21-
}
14+
import java.lang.{Boolean as JBoolean, Byte as JByte, Double as JDouble, Float as JFloat, Long as JLong, Short as JShort}
2215
import java.math.{BigDecimal as JBigDecimal, BigInteger as JBigInteger}
2316
import scala.annotation.{tailrec, threadUnsafe}
2417
import scala.collection.LinearSeq
@@ -55,7 +48,12 @@ object Encoder extends LowPrioEncoders:
5548
/**
5649
* Creates an [[Encoder]] from the given function.
5750
*/
58-
inline def apply[T](implicit encoder: Encoder[T]): Encoder[T] = encoder
51+
inline def apply[T](encoder: Encoder[T]): Encoder[T] = encoder
52+
53+
/**
54+
* Gets a given [[Encoder]] for [[T]].
55+
*/
56+
inline def of[T: Encoder]: Encoder[T] = summon
5957

6058
/**
6159
* Creates an [[Encoder]] that encodes a product instance as a simple array of values.

0 commit comments

Comments
 (0)