Ignore

Struct Ignore 

Source
pub struct Ignore { /* private fields */ }

Implementations§

Source§

impl Ignore

Source

pub fn new(keys: Vec<&str>) -> Self

Examples found in repository?
example/ignore.rs (line 17)
6fn main() {
7    let json = json!(
8        {
9            "explanation": "test",
10            "media_type": "test",
11            "hdurl": "test",
12            "service_version": "test",
13            "code": 200,
14            "msg": "test"
15        }
16    );
17    let values = filter::<Ignore>(json, &Ignore::new(vec!["explanation", "media_type"]));
18    if let Ok(trimmed) = values {
19        println!("TRIMMED: {:#?}", trimmed);
20        assert!(trimmed.get("explanation").is_none());
21        assert!(trimmed.get("media_type").is_none());
22        assert!(trimmed.get("hdurl").is_some());
23    } else {
24        panic!();
25    }
26
27    let json = json!({
28        "2020-01-01": {
29            "explanation": "test_1",
30            "media_type": "test",
31            "hdurl": "test",
32            "service_version": "test",
33            "code": 200,
34            "msg": "test"
35        },
36        "Object": {
37            "2023-01-11": {
38                "Object": {
39                    "explanation": "test_3",
40                    "media_type": "test",
41                    "hdurl": "test",
42                    "service_version": "test",
43                    "code": 200,
44                    "msg": "test"
45                },
46                "explanation": "test_2",
47            }
48        },
49        "explanation": "test_0"
50    });
51
52    let ignore = Ignore::new(vec!["explanation"]);
53    let trimmed = filter::<Ignore>(json, &ignore).unwrap();
54    println!("TRIMMED: {:#?}", trimmed);
55    assert!(trimmed["2020-01-01"].get("explanation").is_none(), "test_1");
56    assert!(
57        trimmed["Object"]["2023-01-11"]["Object"]
58            .get("explanation")
59            .is_none(),
60        "test_3"
61    );
62    assert!(
63        trimmed["Object"]["2023-01-11"].get("explanation").is_none(),
64        "test_2"
65    );
66    assert!(trimmed.get("explanation").is_none(), "test_0");
67}
Source

pub fn sift(json: &Value, ignore_keys: &HashSet<String>) -> Value

Trait Implementations§

Source§

impl Clone for Ignore

Source§

fn clone(&self) -> Ignore

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Ignore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Ignore

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Filter for Ignore

Source§

type Output = Value

Source§

fn filter(&self, json: Value) -> Result<Self::Output, Error>

Source§

impl PartialEq for Ignore

Source§

fn eq(&self, other: &Ignore) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Ignore

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Ignore

Auto Trait Implementations§

§

impl Freeze for Ignore

§

impl RefUnwindSafe for Ignore

§

impl Send for Ignore

§

impl Sync for Ignore

§

impl Unpin for Ignore

§

impl UnwindSafe for Ignore

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,