Building a search endpoint with rocket that searchs in a JSON object

I'm using rocket to build a search method that finds values from my redis cache. A redis cache entry looks like this:

    "key": "40:a3:cc:a3:dc:43",
    "value": {
        "token": "2a256356",
        "change": "new",
        "data": {
                "dns": "", 
                "mac": "40:a3:cc:a3:dc:43", 
                "src": "", 
                "dst": ""

I'm currently using the get() function to find the values from my JSON object like this:

pub fn filter(search: SearchParams, id: &str) -> Vec<Data> {
    let user: Data = get_user(store, id);
    let SearchParams { value, done } = search;
    let data = Data {
        key: id.to_string(),
        value: user.value.get(&value.to_lowercase()).unwrap().clone(),
        done: done.unwrap()

    let mut data_vec: Vec<Data> = Vec::new();


Is there a "cleaner" or better way to do this? My thoughts go into a way using State to store the user and then filtering the value with .iter().filter(). But this does not work. If I try to use this then I always get the complete JSON object instead of the specific searched keys.

             &&|done| done == user.done).unwrap_or(true)

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.