tg_flows/types/
label_price.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
7pub struct LabeledPrice {
8 pub label: String,
10
11 pub amount: i32,
20}
21
22impl LabeledPrice {
23 pub fn new<S>(label: S, amount: i32) -> Self
24 where
25 S: Into<String>,
26 {
27 Self { label: label.into(), amount }
28 }
29
30 pub fn label<S>(mut self, val: S) -> Self
31 where
32 S: Into<String>,
33 {
34 self.label = val.into();
35 self
36 }
37
38 #[must_use]
39 pub fn amount(mut self, val: i32) -> Self {
40 self.amount = val;
41 self
42 }
43}
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn serialize() {
51 let labeled_price = LabeledPrice { label: "Label".to_string(), amount: 60 };
52 let expected = r#"{"label":"Label","amount":60}"#;
53 let actual = serde_json::to_string(&labeled_price).unwrap();
54 assert_eq!(actual, expected);
55 }
56}