1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use serde::{Deserialize, Deserializer};
#[derive(Debug, PartialEq, Eq, Clone, Hash, Deserialize)]
#[non_exhaustive]
pub struct Invoice {
pub title: String,
pub description: String,
#[serde(deserialize_with = "deserialize_start_parameter")]
pub start_parameter: Option<String>,
pub currency: String,
pub total_amount: u32,
}
fn deserialize_start_parameter<'de, D>(
deserializer: D,
) -> Result<Option<String>, D::Error>
where
D: Deserializer<'de>,
{
let string = String::deserialize(deserializer)?;
Ok(if string.is_empty() {
None
} else {
Some(string)
})
}