Made scheduled transactions more generic.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum TransactionDirection {
|
||||
In,
|
||||
Out,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TransactionDirectionConversionError(pub String);
|
||||
|
||||
impl std::fmt::Display for TransactionDirectionConversionError {
|
||||
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(formatter, "invalid direction value: {}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for TransactionDirectionConversionError {}
|
||||
|
||||
impl TryFrom<String> for TransactionDirection {
|
||||
type Error = TransactionDirectionConversionError;
|
||||
|
||||
fn try_from(value: String) -> Result<Self, Self::Error> {
|
||||
match value.as_str() {
|
||||
"in" => Ok(Self::In),
|
||||
"out" => Ok(Self::Out),
|
||||
_ => Err(TransactionDirectionConversionError(value)),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user