49 lines
1.3 KiB
Rust
49 lines
1.3 KiB
Rust
use std::collections::HashMap;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::{
|
|
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
|
common::Uri,
|
|
request_tokenizer::RequestTokenizer,
|
|
response_tokenizer::{ResponseAttributes, get_and_parse_property},
|
|
};
|
|
|
|
pub struct Rescan;
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
pub struct RescanResponse {
|
|
pub updating_db: usize,
|
|
}
|
|
|
|
impl Command for Rescan {
|
|
type Request = Option<Uri>;
|
|
type Response = RescanResponse;
|
|
const COMMAND: &'static str = "rescan";
|
|
|
|
fn serialize_request(&self, request: Self::Request) -> String {
|
|
match request {
|
|
Some(uri) => format!("{} {}", Self::COMMAND, uri),
|
|
None => Self::COMMAND.to_string(),
|
|
}
|
|
}
|
|
|
|
fn parse_request(mut parts: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
|
let uri = parts.next().map(|s| s.to_string());
|
|
|
|
debug_assert!(parts.next().is_none());
|
|
|
|
Ok((Request::Rescan(uri), ""))
|
|
}
|
|
|
|
fn parse_response(
|
|
parts: ResponseAttributes<'_>,
|
|
) -> Result<Self::Response, ResponseParserError<'_>> {
|
|
let parts: HashMap<_, _> = parts.into();
|
|
|
|
let updating_db = get_and_parse_property!(parts, "updating_db", Text);
|
|
|
|
Ok(RescanResponse { updating_db })
|
|
}
|
|
}
|