-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into simplify_scala3_pro…
…duct_derivation
- Loading branch information
Showing
92 changed files
with
1,941 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ OrganizeImports { | |
importSelectorsOrder = Ascii | ||
importsOrder = Ascii | ||
removeUnused = false | ||
targetDialect = Scala2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package pureconfig | ||
|
||
trait ReaderDerives { | ||
// `derives` clauses are only supported in Scala 3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package pureconfig | ||
|
||
import scala.deriving.Mirror | ||
|
||
import pureconfig.generic.derivation._ | ||
|
||
trait ReaderDerives { | ||
inline def derived[A](using m: Mirror.Of[A]): ConfigReader[A] = | ||
ConfigReaderDerivation.Default.deriveConfigReader[A] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
core/src/main/scala-3/pureconfig/generic/derivation/EnumConfigConvert.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package pureconfig | ||
package generic | ||
package derivation | ||
|
||
import scala.deriving.Mirror | ||
|
||
import com.typesafe.config.ConfigValue | ||
|
||
trait EnumConfigConvert[A] extends ConfigConvert[A] | ||
|
||
object EnumConfigConvert { | ||
inline def derived[A: Mirror.SumOf]: EnumConfigConvert[A] = | ||
new EnumConfigConvert[A] { | ||
val reader = EnumConfigReaderDerivation.Default.EnumConfigReader.derived[A] | ||
val writer = EnumConfigWriterDerivation.Default.EnumConfigWriter.derived[A] | ||
|
||
def from(cur: ConfigCursor): ConfigReader.Result[A] = reader.from(cur) | ||
def to(a: A): ConfigValue = writer.to(a) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
core/src/main/scala-3/pureconfig/generic/derivation/EnumConfigWriterDerivation.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package pureconfig | ||
package generic | ||
package derivation | ||
|
||
import scala.compiletime.{constValue, erasedValue, error, summonInline} | ||
import scala.deriving.Mirror | ||
|
||
import com.typesafe.config.{ConfigValue, ConfigValueFactory} | ||
|
||
import pureconfig.error.{CannotConvert, ConfigReaderFailures} | ||
import pureconfig.generic.derivation.Utils._ | ||
|
||
type EnumConfigWriter[A] = EnumConfigWriterDerivation.Default.EnumConfigWriter[A] | ||
|
||
trait EnumConfigWriterDerivation(transformName: String => String) { | ||
|
||
trait EnumConfigWriter[A] extends ConfigWriter[A] | ||
|
||
object EnumConfigWriter { | ||
inline def derived[A](using m: Mirror.SumOf[A]): EnumConfigWriter[A] = | ||
new EnumConfigWriter[A] { | ||
assertIsEnum[m.MirroredElemTypes] | ||
val labels = transformedLabels[A](transformName).toVector | ||
|
||
def to(a: A): ConfigValue = | ||
ConfigValueFactory.fromAnyRef(labels(m.ordinal(a))) | ||
} | ||
} | ||
|
||
private inline def assertIsEnum[T <: Tuple]: Unit = | ||
inline erasedValue[T] match { | ||
case _: (h *: t) => | ||
inline summonInline[Mirror.Of[h]] match { | ||
case m: Mirror.Singleton => assertIsEnum[t] | ||
case _ => error("Enums cannot include parameterized cases.") | ||
} | ||
case _: EmptyTuple => () | ||
} | ||
} | ||
|
||
object EnumConfigWriterDerivation { | ||
object Default extends EnumConfigWriterDerivation(ConfigFieldMapping(PascalCase, KebabCase)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
core/src/main/scala-3/pureconfig/generic/derivation/Utils.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.