clean up imports

This commit is contained in:
kageru 2020-06-20 22:08:33 +02:00
parent d4f86ee393
commit 5c3a815ba8
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
2 changed files with 17 additions and 10 deletions

View File

@ -8,6 +8,14 @@ pub struct Error {
pub message: String,
}
impl Error {
pub fn from_str(message: &str) -> Self {
Error {
message: message.to_string(),
}
}
}
impl de::Error for Error {
fn custom<T: Display>(msg: T) -> Self {
Error {

View File

@ -2,13 +2,14 @@ use serde::de;
use serde::de::value::MapDeserializer;
use serde::forward_to_deserialize_any;
use serde::Deserialize;
use std::collections::HashMap;
use std::fmt;
use std::time::Duration;
mod error;
use error::MpdResult;
use error::{MpdResult,Error};
struct MPDeserializer<'de, Iter: Iterator<Item = (&'de str, &'de str)>> {
inner: MapDeserializer<'de, Iter, error::Error>,
inner: MapDeserializer<'de, Iter, Error>,
}
/// Deserialize time from an integer that represents the seconds.
@ -89,7 +90,7 @@ const SEPARATOR: char = '\x02';
impl<'de, Iter: Iterator<Item = (&'de str, &'de str)>> de::Deserializer<'de>
for MPDeserializer<'de, Iter>
{
type Error = error::Error;
type Error = Error;
fn deserialize_any<V>(self, visitor: V) -> MpdResult<V::Value>
where
@ -136,15 +137,13 @@ where
deserializer.deserialize_any(StringOrVec())
}
fn deserialize_response<'a, I: Iterator<Item = &'a str>>(input: I) -> Result<Track, error::Error> {
let mut map: std::collections::HashMap<String, String> = std::collections::HashMap::new();
fn deserialize_response<'a, I: Iterator<Item = &'a str>>(input: I) -> Result<Track, Error> {
let mut map: HashMap<String, String> = HashMap::new();
for line in input {
if let Some(_) = line.strip_prefix("OK") {
if line.starts_with("OK") {
break;
} else if let Some(message) = line.strip_prefix("ACK") {
return Err(error::Error {
message: message.trim().to_string(),
});
return Err(Error::from_str(message.trim()));
}
let mut fields = line.splitn(2, ": ");
match (fields.next(), fields.next()) {
@ -167,7 +166,7 @@ fn deserialize_response<'a, I: Iterator<Item = &'a str>>(input: I) -> Result<Tra
}
fn main() {
let input_str = "file: Youtube Rip/VVVVVV Medley.flac
let input_str = "file: Youtube Rip/VVVVVV Medley.flac
Last-Modified: 2018-03-07T13:18:01Z
Album: VVVVVV OST / PPPPPP
Artist: FamilyJules7x