paypal_rust/resources/
patch.rs1use serde::{Deserialize, Serialize};
2use serde_with::skip_serializing_none;
3
4use crate::resources::enums::op::Op;
5use crate::resources::money::Money;
6
7#[skip_serializing_none]
8#[derive(Clone, Debug, Default, Deserialize, Serialize)]
9pub struct Patch {
10 pub op: Op,
12
13 pub path: Option<String>,
15
16 pub value: Option<PatchValue>,
18
19 pub from: Option<String>,
21}
22
23impl Patch {
24 pub fn new(op: Op) -> Self {
25 Self {
26 op,
27 ..Default::default()
28 }
29 }
30
31 #[must_use]
32 pub fn path(mut self, path: String) -> Self {
33 self.path = Some(path);
34 self
35 }
36
37 #[must_use]
38 pub fn value(mut self, value: PatchValue) -> Self {
39 self.value = Some(value);
40 self
41 }
42
43 #[must_use]
44 pub fn from(mut self, from: String) -> Self {
45 self.from = Some(from);
46 self
47 }
48}
49
50#[derive(Debug, Deserialize, Serialize, Clone)]
51#[serde(untagged)]
52pub enum PatchValue {
53 Int(i32),
54 Boolean(bool),
55 String(String),
56 Vec(Vec<PatchValue>),
57 Money(Money),
58}
59
60impl PatchValue {
61 #[must_use]
62 pub fn money(self, money: Money) -> Self {
63 Self::Money(money)
64 }
65
66 #[must_use]
67 pub fn string(self, string: String) -> Self {
68 Self::String(string)
69 }
70
71 #[must_use]
72 pub fn bool(self, boolean: bool) -> Self {
73 Self::Boolean(boolean)
74 }
75
76 #[must_use]
77 pub fn vec(self, vec: Vec<PatchValue>) -> Self {
78 Self::Vec(vec)
79 }
80
81 #[must_use]
82 pub fn int(self, int: i32) -> Self {
83 Self::Int(int)
84 }
85}