message: add FromStr for the cardano's Coin
diff: @@ -19,12 +19,15 @@ pub enum Error {
  /// Max bound being: `MAX_COIN`.
  OutOfBound(u64),
  + ParseIntError,
  +
  Negative
  }
  impl fmt::Display for Error {
  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  match self {
  &Error::OutOfBound(ref v) => write!(f, "Coin of value {} is out of bound. Max coin value: {}.", v, MAX_COIN),
  + &Error::ParseIntError => write!(f, "Cannot parse a valid integer"),
  &Error::Negative => write!(f, "Coin cannot hold a negative value"),
  }
  }
  @@ -85,6 +88,16 @@ impl fmt::Display for Coin {
  write!(f, "{}.{:06}", self.0 / 1000000, self.0 % 1000000)
  }
  }
  +impl ::std::str::FromStr for Coin {
  + type Err = Error;
  + fn from_str(s: &str) -> result::Result<Self, Self::Err> {
  + let v : u64 = match s.parse() {
  + Err(_) => return Err(Error::ParseIntError),
  + Ok(v) => v
  + };
  + Coin::new(v)
  + }
  +}
  impl cbor_event::se::Serialize for Coin {
  fn serialize<W: ::std::io::Write>(&self, serializer: Serializer<W>) -> cbor_event::Result<Serializer<W>> {
  serializer.write_unsigned_integer(self.0)
  