some cleanup
This commit is contained in:
parent
7bceb3afc8
commit
117d552939
35
src/main.rs
35
src/main.rs
@ -1,10 +1,8 @@
|
||||
#[macro_use]
|
||||
extern crate pest_derive;
|
||||
use pest::iterators::Pair;
|
||||
use pest::Parser;
|
||||
use serde::de;
|
||||
use serde::de::value::MapDeserializer;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::forward_to_deserialize_any;
|
||||
use serde::Deserialize;
|
||||
mod error;
|
||||
@ -14,11 +12,11 @@ use error::MpdResult;
|
||||
#[grammar = "response.pest"]
|
||||
struct MpdParser;
|
||||
|
||||
struct MPDeserializer<'de, Iter: Iterator<Item = (String, String)>> {
|
||||
struct MPDeserializer<'de, Iter: Iterator<Item = (&'de str, &'de str)>> {
|
||||
inner: MapDeserializer<'de, Iter, error::Error>,
|
||||
}
|
||||
|
||||
impl<'de, Iter: Iterator<Item = (String, String)>> de::Deserializer<'de>
|
||||
impl<'de, Iter: Iterator<Item = (&'de str, &'de str)>> de::Deserializer<'de>
|
||||
for MPDeserializer<'de, Iter>
|
||||
{
|
||||
type Error = error::Error;
|
||||
@ -45,15 +43,12 @@ impl<'de, Iter: Iterator<Item = (String, String)>> de::Deserializer<'de>
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
struct Song {
|
||||
Title: String,
|
||||
Artist: String,
|
||||
title: String,
|
||||
artist: String,
|
||||
}
|
||||
|
||||
const input_var: &str = "Title: A song 星
|
||||
Artist: A name
|
||||
OK mpd 0.21.23";
|
||||
|
||||
fn main() {
|
||||
/*
|
||||
let parsed = MpdParser::parse(Rule::response, input)
|
||||
@ -75,30 +70,32 @@ fn main() {
|
||||
let d = Song::deserialize(&mut deser);
|
||||
println!("{:?}", d);
|
||||
*/
|
||||
let input_var: &str = "Title: A song 星
|
||||
Artist: A name
|
||||
OK mpd 0.21.23";
|
||||
|
||||
let mut map = std::collections::HashMap::new();
|
||||
let parser = MpdParser::parse(Rule::response, input_var)
|
||||
.unwrap()
|
||||
.next()
|
||||
.unwrap();
|
||||
for pair in parser.into_inner() {
|
||||
let rule = pair.as_rule();
|
||||
match rule {
|
||||
for line in parser.into_inner() {
|
||||
match line.as_rule() {
|
||||
Rule::kv => {
|
||||
let mut fields = pair.into_inner();
|
||||
let mut fields = line.into_inner();
|
||||
map.insert(
|
||||
fields.next().unwrap().as_str().to_string(),
|
||||
fields.next().unwrap().as_str().to_string(),
|
||||
fields.next().unwrap().as_str(),
|
||||
fields.next().unwrap().as_str(),
|
||||
);
|
||||
}
|
||||
Rule::ok => (),
|
||||
Rule::ok => break,
|
||||
Rule::err => panic!("received error response"),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
// ::<'_, _, Song>
|
||||
dbg!(&map);
|
||||
let deser = MPDeserializer {
|
||||
inner: serde::de::value::MapDeserializer::new(map.into_iter()),
|
||||
inner: MapDeserializer::new(map.into_iter()),
|
||||
};
|
||||
let s = Song::deserialize(deser);
|
||||
println!("{:?}", s);
|
||||
|
Loading…
Reference in New Issue
Block a user