baskerville / plato

Document reader
Other
1.26k stars 105 forks source link

Duplicate event Type for searches #254

Open ju6ge opened 2 years ago

ju6ge commented 2 years ago

Hi, I am currently in the process of writing a custom fetcher. In the process I noticed, that the event type for the serach and its results are identical. This is inconvenient for Event serialization, it would be better to use different identifiers for the search request and the search results.

Current State

#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "type")]
pub enum PlatoEvent {
    #[serde(rename="notify")]
    Notification {
        message: String
    },

    #[serde(rename="setWifi")]
    Wifi {
        enabled: bool
    },

    #[serde(rename="search")]
    Search {
        path: String,
        query: String,
        sortBy: (String, bool)
    },

    #[serde(rename="search")]
    SearchResults {
        result: String,
    }
}

The result is that when serde tries do deserialize the SerachResult event received it thinks it is of type Search and complains about missing fields: Error: missing field 'path'.

It would be far better if the Event type was unique like so:

#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "type")]
pub enum PlatoEvent {
    #[serde(rename="notify")]
    Notification {
        message: String
    },

    #[serde(rename="setWifi")]
    Wifi {
        enabled: bool
    },

    #[serde(rename="search")]
    Search {
        path: String,
        query: String,
        sortBy: (String, bool)
    },

    #[serde(rename="searchresult")]
    SearchResults {
        result: String,
    }
}

Kind regads, ju6ge