feat: get amount
This commit is contained in:
@@ -1,7 +1,23 @@
|
||||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
use serde::{de, Deserialize, Deserializer};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Params {
|
||||
#[serde(default, deserialize_with="empty_string_as_none")]
|
||||
transaction_id: Option<i64>,
|
||||
}
|
||||
pub transaction_id: Option<i64>,
|
||||
}
|
||||
|
||||
// Serde deserialization decorator to map empty Strings to None,
|
||||
fn empty_string_as_none<'de, D, T>(de: D) -> Result<Option<T>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
T: FromStr,
|
||||
T::Err: fmt::Display,
|
||||
{
|
||||
let opt = Option::<String>::deserialize(de)?;
|
||||
match opt.as_deref() {
|
||||
None | Some("") => Ok(None),
|
||||
Some(s) => FromStr::from_str(s).map_err(de::Error::custom).map(Some),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user