1
use std::collections::HashMap;
2

            
3
use crate::commands::{
4
    get_and_parse_property, Command, Request, RequestParserResult, ResponseAttributes,
5
    ResponseParserError,
6
};
7

            
8
pub struct Rescan;
9

            
10
pub struct RescanResponse {
11
    pub updating_db: usize,
12
}
13

            
14
impl Command for Rescan {
15
    type Response = RescanResponse;
16
    const COMMAND: &'static str = "rescan";
17

            
18
    fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
19
        let uri = parts.next().map(|s| s.to_string());
20

            
21
        debug_assert!(parts.next().is_none());
22

            
23
        Ok((Request::Rescan(uri), ""))
24
    }
25

            
26
    fn parse_response(
27
        parts: ResponseAttributes<'_>,
28
    ) -> Result<Self::Response, ResponseParserError> {
29
        let parts: HashMap<_, _> = parts.into();
30

            
31
        let updating_db = get_and_parse_property!(parts, "updating_db", Text);
32

            
33
        Ok(RescanResponse { updating_db })
34
    }
35
}