paypal_rust/resources/enums/op.rs
1use serde::{Deserialize, Serialize};
2
3#[derive(Copy, Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
4pub enum Op {
5 /// Depending on the target location reference, completes one of these functions:
6 /// 1. The target location is an array index. Inserts a new value into the array at the specified index.
7 /// 2. The target location is an object parameter that does not already exist. Adds a new parameter to the object.
8 /// 3. The target location is an object parameter that does exist. Replaces that parameter's value.
9 /// 4. The value parameter defines the value to add. For more information, see 4.1. add.
10 #[default]
11 #[serde(rename = "add")]
12 Add,
13 /// Removes the value at the target location. For the operation to succeed, the target location must exist.
14 #[serde(rename = "remove")]
15 Remove,
16 /// Replaces the value at the target location with a new value. The operation object must contain a value parameter that
17 /// defines the replacement value. For the operation to succeed, the target location must exist.
18 #[serde(rename = "replace")]
19 Replace,
20 /// Removes the value at a specified location and adds it to the target location. The operation object must contain a from
21 /// parameter, which is a string that contains a JSON pointer value that references the location in the target document from which to
22 /// move the value. For the operation to succeed, the from location must exist.
23 #[serde(rename = "move")]
24 Move,
25 /// Copies the value at a specified location to the target location. The operation object must contain a from parameter,
26 /// which is a string that contains a JSON pointer value that references the location in the target document from which to copy the
27 /// value. For the operation to succeed, the from location must exist.
28 #[serde(rename = "copy")]
29 Copy,
30 /// Tests that a value at the target location is equal to a specified value. The operation object must contain a value
31 /// parameter that defines the value to compare to the target location's value. For the operation to succeed, the target location must
32 /// be equal to the value value. For test, equal indicates that the value at the target location and the value that value defines are of
33 /// the same JSON type. The data type of the value determines how equality is defined:
34 /// * **strings** Contain the same number of Unicode characters and their code points are byte-by-byte equal.
35 /// * **numbers** Are numerically equal.
36 /// * **arrays** Contain the same number of values, and each value is equal to the value at the corresponding position in the other array,
37 /// by using these type-specific rules.
38 /// * **objects** Contain the same number of parameters, and each parameter is
39 /// * **equal** to a parameter in the other object, by comparing their keys (as strings) and their values (by using these type-specific rules).
40 /// * **literals** (false, true, and null) Are the same. The comparison is a
41 /// logical comparison. For example, whitespace between the parameter values of an array is not significant.
42 /// Also, ordering of the serialization of object parameters is not significant.
43 #[serde(rename = "test")]
44 Test,
45}
46
47impl Op {
48 pub const fn as_str(self) -> &'static str {
49 match self {
50 Self::Add => "add",
51 Self::Remove => "remove",
52 Self::Replace => "replace",
53 Self::Move => "move",
54 Self::Copy => "copy",
55 Self::Test => "test",
56 }
57 }
58}
59
60impl AsRef<str> for Op {
61 fn as_ref(&self) -> &str {
62 self.as_str()
63 }
64}
65
66impl std::fmt::Display for Op {
67 fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
68 self.as_str().fmt(formatter)
69 }
70}