Lines
0 %
Functions
use crate::{
commands::{
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError,
},
common::TimeWithFractions,
request::SeekMode,
};
pub struct SeekCur;
impl Command for SeekCur {
type Response = ();
const COMMAND: &'static str = "seekcur";
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
let time_raw = match parts.next() {
Some(t) => t,
None => return Err(RequestParserError::UnexpectedEOF),
// TODO: DRY
let (mode, time) = match time_raw {
t if t.starts_with('+') => (
SeekMode::Relative,
t[1..]
.parse::<TimeWithFractions>()
.map_err(|_| RequestParserError::SyntaxError(0, t.to_owned()))?,
),
t if t.starts_with('-') => (
-t[1..]
t => (
SeekMode::Absolute,
t.parse::<TimeWithFractions>()
debug_assert!(parts.next().is_none());
Ok((Request::SeekCur(mode, time), ""))
}
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty());
Ok(())