mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-23 22:56:52 +01:00
Add StringFactory trait (#1537)
This commit is contained in:
parent
f9f1e89a07
commit
5c2fb8f580
1 changed files with 20 additions and 0 deletions
|
@ -0,0 +1,20 @@
|
|||
package org.bitcoins.crypto
|
||||
|
||||
import scala.util.Try
|
||||
|
||||
/** A common factory trait that can be re-used to deserialize a string to a type t */
|
||||
trait StringFactory[T] {
|
||||
|
||||
/** Tries to parse a string to type t, throws an exception if fails */
|
||||
def fromString(string: String): T
|
||||
|
||||
/** Treis to parse a string to type t, returns None if failure */
|
||||
def fromStringOpt(string: String): Option[T] = {
|
||||
fromStringT(string).toOption
|
||||
}
|
||||
|
||||
/** Tries to parsea string to type t, returns [[scala.util.Failure]] if the fails */
|
||||
def fromStringT(string: String): Try[T] = {
|
||||
Try(fromString(string))
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue