-
Notifications
You must be signed in to change notification settings - Fork 78
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/main' into feat/muxed_keys
- Loading branch information
Showing
6 changed files
with
46 additions
and
9 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
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,35 @@ | ||
use std::str::FromStr; | ||
|
||
#[derive(Clone, Debug, Copy)] | ||
pub struct Amount(i64); | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
#[error("cannot start or end with `_`: {0}")] | ||
CannotStartOrEndWithUnderscore(String), | ||
#[error(transparent)] | ||
IntParse(#[from] std::num::ParseIntError), | ||
} | ||
|
||
impl FromStr for Amount { | ||
type Err = Error; | ||
|
||
fn from_str(value: &str) -> Result<Self, Self::Err> { | ||
if value.starts_with('_') || value.ends_with('_') { | ||
return Err(Error::CannotStartOrEndWithUnderscore(value.to_string())); | ||
} | ||
Ok(Self(value.replace('_', "").parse::<i64>()?)) | ||
} | ||
} | ||
|
||
impl From<Amount> for i64 { | ||
fn from(builder: Amount) -> Self { | ||
builder.0 | ||
} | ||
} | ||
|
||
impl From<&Amount> for i64 { | ||
fn from(builder: &Amount) -> Self { | ||
(*builder).into() | ||
} | ||
} |