Mild renaming

This commit is contained in:
Erick Tryzelaar 2014-10-06 21:37:25 -07:00
parent 90d3918904
commit 447163834c
2 changed files with 34 additions and 54 deletions

View File

@ -154,20 +154,21 @@ struct MySeqVisitor {
impl<
Iter: Iterator<Token>,
> de2::SeqVisitor<MyDeserializer<Iter>, Error> for MySeqVisitor {
fn next<
fn visit<
T: Deserialize<MyDeserializer<Iter>, Error>
>(&mut self, d: &mut MyDeserializer<Iter>) -> option::Option<Result<T, Error>> {
>(&mut self, d: &mut MyDeserializer<Iter>) -> Result<option::Option<T>, Error> {
match d.peek() {
Some(&End) => {
d.next();
None
Ok(None)
}
Some(_) => {
self.len -= 1;
Some(Deserialize::deserialize(d))
let value = try!(Deserialize::deserialize(d));
Ok(Some(value))
}
None => {
Some(Err(d.syntax_error()))
Err(d.syntax_error())
}
}
}
@ -192,32 +193,25 @@ struct MyMapVisitor {
impl<
Iter: Iterator<Token>,
> de2::MapVisitor<MyDeserializer<Iter>, Error> for MyMapVisitor {
fn next<
fn visit<
K: Deserialize<MyDeserializer<Iter>, Error>,
V: Deserialize<MyDeserializer<Iter>, Error>,
>(&mut self, d: &mut MyDeserializer<Iter>) -> option::Option<Result<(K, V), Error>> {
>(&mut self, d: &mut MyDeserializer<Iter>) -> Result<option::Option<(K, V)>, Error> {
match d.peek() {
Some(&End) => {
d.next();
None
Ok(None)
}
Some(_) => {
self.len -= 1;
let key = match Deserialize::deserialize(d) {
Ok(key) => key,
Err(err) => { return Some(Err(err)); }
};
let key = try!(Deserialize::deserialize(d));
let value = try!(Deserialize::deserialize(d));
let value = match Deserialize::deserialize(d) {
Ok(value) => value,
Err(err) => { return Some(Err(err)); }
};
Some(Ok((key, value)))
Ok(Some((key, value)))
}
None => {
Some(Err(d.syntax_error()))
Err(d.syntax_error())
}
}
}
@ -238,7 +232,7 @@ impl<
///////////////////////////////////////////////////////////////////////////////
mod json {
//use std::collections::TreeMap;
use std::collections::TreeMap;
use serde2::de2;
#[deriving(Show)]
@ -248,7 +242,7 @@ mod json {
Int(int),
//String(String),
List(Vec<Value>),
//Map(TreeMap<String, Value>),
Map(TreeMap<String, Value>),
}
impl<
@ -292,9 +286,9 @@ mod json {
let mut values = Vec::with_capacity(len);
loop {
match visitor.next(d) {
match try!(visitor.visit(d)) {
Some(value) => {
values.push(try!(value));
values.push(value);
}
None => {
break;
@ -305,21 +299,16 @@ mod json {
Ok(List(values))
}
/*
fn visit_map<
Visitor: ::MapVisitor<D, E>,
Visitor: de2::MapVisitor<D, E>,
>(&mut self, d: &mut D, mut visitor: Visitor) -> Result<Value, E> {
let mut values = TreeMap::new();
loop {
let kv: Option<Result<(String, Value), E>> = visitor.next(d);
match kv {
Some(Ok((key, value))) => {
match try!(visitor.visit(d)) {
Some((key, value)) => {
values.insert(key, value);
}
Some(Err(err)) => {
return Err(err);
}
None => {
break;
}
@ -328,7 +317,6 @@ mod json {
Ok(Map(values))
}
*/
}
d.visit(&mut Visitor)
@ -473,7 +461,6 @@ fn main() {
let v: Result<HashMap<string::String, int>, Error> = Deserialize::deserialize(&mut state);
println!("{}", v);
/*
////
let tokens = vec!(
@ -488,7 +475,6 @@ fn main() {
let v: Result<json::Value, Error> = Deserialize::deserialize(&mut state);
println!("{}", v);
*/
}

View File

@ -68,9 +68,9 @@ pub trait OptionVisitor<D, E> {
}
pub trait SeqVisitor<D, E> {
fn next<
fn visit<
T: Deserialize<D, E>,
>(&mut self, d: &mut D) -> Option<Result<T, E>>;
>(&mut self, d: &mut D) -> Result<Option<T>, E>;
fn end(&mut self, d: &mut D) -> Result<(), E>;
@ -81,10 +81,10 @@ pub trait SeqVisitor<D, E> {
}
pub trait MapVisitor<D, E> {
fn next<
fn visit<
K: Deserialize<D, E>,
V: Deserialize<D, E>,
>(&mut self, d: &mut D) -> Option<Result<(K, V), E>>;
>(&mut self, d: &mut D) -> Result<Option<(K, V)>, E>;
fn end(&mut self, d: &mut D) -> Result<(), E>;
@ -199,9 +199,9 @@ impl<
let mut values = Vec::with_capacity(len);
loop {
match visitor.next(d) {
match try!(visitor.visit(d)) {
Some(value) => {
values.push(try!(value));
values.push(value);
}
None => {
break;
@ -243,9 +243,9 @@ impl<
match state {
0 => {
state += 1;
match visitor.next(d) {
match try!(visitor.visit(d)) {
Some(value) => {
t0 = Some(try!(value));
t0 = Some(value);
}
None => {
return Err(d.end_of_stream_error());
@ -254,9 +254,9 @@ impl<
}
1 => {
state += 1;
match visitor.next(d) {
match try!(visitor.visit(d)) {
Some(value) => {
t1 = Some(try!(value));
t1 = Some(value);
}
None => {
return Err(d.end_of_stream_error());
@ -301,13 +301,10 @@ impl<
let mut values = HashMap::with_capacity(len);
loop {
match visitor.next(d) {
Some(Ok((key, value))) => {
match try!(visitor.visit(d)) {
Some((key, value)) => {
values.insert(key, value);
}
Some(Err(err)) => {
return Err(err);
}
None => {
break;
}
@ -343,13 +340,10 @@ impl<
let mut values = TreeMap::new();
loop {
match visitor.next(d) {
Some(Ok((key, value))) => {
match try!(visitor.visit(d)) {
Some((key, value)) => {
values.insert(key, value);
}
Some(Err(err)) => {
return Err(err);
}
None => {
break;
}