From 1ac8d8e71c67ce58d79ba0aa3600a18cd9da0ba3 Mon Sep 17 00:00:00 2001 From: Markus Klink Date: Tue, 16 Feb 2016 20:00:23 +0100 Subject: [PATCH] Hide implicit CSVFormat in dedicated object This avoids ambigous implicit instances --- README.md | 1 + src/main/scala/com/github/tototoshi/csv/CSVFormat.scala | 5 +++++ src/main/scala/com/github/tototoshi/csv/package.scala | 4 +++- src/test/scala/com/github/tototoshi/csv/CSVReaderSpec.scala | 1 + src/test/scala/com/github/tototoshi/csv/CSVWriterSpec.scala | 1 + 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a5a7a63..e3c8fba 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ libraryDependencies += "com.github.tototoshi" %% "scala-csv" % "1.3.0-SNAPSHOT" ```scala scala> import com.github.tototoshi.csv._ +scala> import implicits._ // for a default CSVFormat instance ``` ### Reading example diff --git a/src/main/scala/com/github/tototoshi/csv/CSVFormat.scala b/src/main/scala/com/github/tototoshi/csv/CSVFormat.scala index 9ce4b85..84efc34 100644 --- a/src/main/scala/com/github/tototoshi/csv/CSVFormat.scala +++ b/src/main/scala/com/github/tototoshi/csv/CSVFormat.scala @@ -15,6 +15,11 @@ */ package com.github.tototoshi.csv +import scala.annotation.implicitNotFound + +@implicitNotFound( + "Cannot find implicit instance of com.github.tototoshi.csv.CSVFormat. Create your own, or import com.github.tototoshi.csv.implicits._" +) trait CSVFormat { val delimiter: Char diff --git a/src/main/scala/com/github/tototoshi/csv/package.scala b/src/main/scala/com/github/tototoshi/csv/package.scala index 1e4fa19..24bb0ed 100644 --- a/src/main/scala/com/github/tototoshi/csv/package.scala +++ b/src/main/scala/com/github/tototoshi/csv/package.scala @@ -18,6 +18,8 @@ package com.github.tototoshi package object csv { - implicit val defaultCSVFormat = new DefaultCSVFormat {} + object implicits { + implicit val defaultCSVFormat: CSVFormat = new DefaultCSVFormat {} + } } diff --git a/src/test/scala/com/github/tototoshi/csv/CSVReaderSpec.scala b/src/test/scala/com/github/tototoshi/csv/CSVReaderSpec.scala index 691edfd..46aeef4 100644 --- a/src/test/scala/com/github/tototoshi/csv/CSVReaderSpec.scala +++ b/src/test/scala/com/github/tototoshi/csv/CSVReaderSpec.scala @@ -3,6 +3,7 @@ package com.github.tototoshi.csv import java.io.{ UnsupportedEncodingException, FileReader, File, StringReader } import org.scalatest._ +import implicits._ class CSVReaderSpec extends FunSpec with ShouldMatchers with Using { diff --git a/src/test/scala/com/github/tototoshi/csv/CSVWriterSpec.scala b/src/test/scala/com/github/tototoshi/csv/CSVWriterSpec.scala index 8ecc6ca..ba3bb58 100644 --- a/src/test/scala/com/github/tototoshi/csv/CSVWriterSpec.scala +++ b/src/test/scala/com/github/tototoshi/csv/CSVWriterSpec.scala @@ -3,6 +3,7 @@ package com.github.tototoshi.csv import java.io.{ FileOutputStream, UnsupportedEncodingException, FileWriter, File } import org.scalatest._ +import implicits._ class CSVWriterSpec extends FunSpec with ShouldMatchers with BeforeAndAfter with Using {