mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-25 13:57:55 +00:00
Merge pull request #70 from oli-obk/xml_requirements
changes needed for xml parsing
This commit is contained in:
@@ -15,6 +15,7 @@ use serde::de::{self, Deserialize, Deserializer};
|
||||
use serde::json::ser::escape_str;
|
||||
use serde::json;
|
||||
use serde::ser::{self, Serialize, Serializer};
|
||||
use std::str::FromStr;
|
||||
|
||||
use rustc_serialize::Encodable;
|
||||
|
||||
@@ -53,6 +54,11 @@ impl rustc_serialize::Decodable for HttpProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for HttpProtocol {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<HttpProtocol, ()> { unimplemented!() }
|
||||
}
|
||||
|
||||
impl FromPrimitive for HttpProtocol {
|
||||
fn from_i64(i: i64) -> Option<HttpProtocol> {
|
||||
FromPrimitive::from_u64(i as u64)
|
||||
@@ -101,6 +107,11 @@ enum HttpMethod {
|
||||
PATCH,
|
||||
}
|
||||
|
||||
impl FromStr for HttpMethod {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<HttpMethod, ()> { unimplemented!() }
|
||||
}
|
||||
|
||||
impl FromPrimitive for HttpMethod {
|
||||
fn from_i64(i: i64) -> Option<HttpMethod> {
|
||||
FromPrimitive::from_u64(i as u64)
|
||||
@@ -165,6 +176,11 @@ enum CacheStatus {
|
||||
Hit,
|
||||
}
|
||||
|
||||
impl FromStr for CacheStatus {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<CacheStatus, ()> { unimplemented!() }
|
||||
}
|
||||
|
||||
impl FromPrimitive for CacheStatus {
|
||||
fn from_i64(i: i64) -> Option<CacheStatus> {
|
||||
FromPrimitive::from_u64(i as u64)
|
||||
@@ -229,6 +245,11 @@ enum OriginProtocol {
|
||||
HTTPS,
|
||||
}
|
||||
|
||||
impl FromStr for OriginProtocol {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<OriginProtocol, ()> { unimplemented!() }
|
||||
}
|
||||
|
||||
impl FromPrimitive for OriginProtocol {
|
||||
fn from_i64(i: i64) -> Option<OriginProtocol> {
|
||||
FromPrimitive::from_u64(i as u64)
|
||||
@@ -286,6 +307,11 @@ enum ZonePlan {
|
||||
ENT,
|
||||
}
|
||||
|
||||
impl FromStr for ZonePlan {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<ZonePlan, ()> { unimplemented!() }
|
||||
}
|
||||
|
||||
impl FromPrimitive for ZonePlan {
|
||||
fn from_i64(i: i64) -> Option<ZonePlan> {
|
||||
FromPrimitive::from_u64(i as u64)
|
||||
@@ -596,6 +622,11 @@ enum Country {
|
||||
ZW,
|
||||
}
|
||||
|
||||
impl FromStr for Country {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<Country, ()> { unimplemented!() }
|
||||
}
|
||||
|
||||
impl FromPrimitive for Country {
|
||||
fn from_i64(i: i64) -> Option<Country> {
|
||||
FromPrimitive::from_u64(i as u64)
|
||||
|
||||
+21
-3
@@ -4,6 +4,7 @@ use std::marker::PhantomData;
|
||||
use std::path;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use std::str;
|
||||
|
||||
use num::FromPrimitive;
|
||||
|
||||
@@ -56,6 +57,16 @@ impl Visitor for BoolVisitor {
|
||||
{
|
||||
Ok(v)
|
||||
}
|
||||
|
||||
fn visit_str<E>(&mut self, s: &str) -> Result<bool, E>
|
||||
where E: Error,
|
||||
{
|
||||
match s.trim() {
|
||||
"true" => Ok(true),
|
||||
"false" => Ok(false),
|
||||
_ => Err(Error::syntax_error()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deserialize for bool {
|
||||
@@ -96,7 +107,7 @@ impl<T> PrimitiveVisitor<T> {
|
||||
}
|
||||
|
||||
impl<
|
||||
T: Deserialize + FromPrimitive
|
||||
T: Deserialize + FromPrimitive + str::FromStr
|
||||
> Visitor for PrimitiveVisitor<T> {
|
||||
type Value = T;
|
||||
|
||||
@@ -112,6 +123,13 @@ impl<
|
||||
impl_deserialize_num_method!(u64, visit_u64, from_u64);
|
||||
impl_deserialize_num_method!(f32, visit_f32, from_f32);
|
||||
impl_deserialize_num_method!(f64, visit_f64, from_f64);
|
||||
|
||||
#[inline]
|
||||
fn visit_str<E>(&mut self, v: &str) -> Result<T, E>
|
||||
where E: Error,
|
||||
{
|
||||
str::FromStr::from_str(v.trim()).or(Err(Error::syntax_error()))
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_deserialize_num {
|
||||
@@ -394,7 +412,7 @@ impl<T> Deserialize for Vec<T>
|
||||
fn deserialize<D>(deserializer: &mut D) -> Result<Vec<T>, D::Error>
|
||||
where D: Deserializer,
|
||||
{
|
||||
deserializer.visit(VecVisitor::new())
|
||||
deserializer.visit_seq(VecVisitor::new())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -572,7 +590,7 @@ macro_rules! tuple_impls {
|
||||
fn deserialize<D>(deserializer: &mut D) -> Result<($($name,)+), D::Error>
|
||||
where D: Deserializer,
|
||||
{
|
||||
deserializer.visit($visitor { marker: PhantomData })
|
||||
deserializer.visit_seq($visitor { marker: PhantomData })
|
||||
}
|
||||
}
|
||||
)+
|
||||
|
||||
+1
-1
@@ -127,7 +127,7 @@ pub trait Deserializer {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
pub trait Visitor {
|
||||
type Value;
|
||||
type Value: Deserialize;
|
||||
|
||||
fn visit_bool<E>(&mut self, _v: bool) -> Result<Self::Value, E>
|
||||
where E: Error,
|
||||
|
||||
+7
-1
@@ -1,4 +1,5 @@
|
||||
use std::io;
|
||||
use std::iter::Peekable;
|
||||
|
||||
pub struct LineColIterator<Iter: Iterator<Item=io::Result<u8>>> {
|
||||
iter: Iter,
|
||||
@@ -25,12 +26,17 @@ impl<Iter: Iterator<Item=io::Result<u8>>> LineColIterator<Iter> {
|
||||
pub fn get_ref(&self) -> &Iter { &self.iter }
|
||||
|
||||
/// Gets a mutable reference to the underlying iterator.
|
||||
pub fn get_mut(&self) -> &Iter { &self.iter }
|
||||
pub fn get_mut(&mut self) -> &mut Iter { &mut self.iter }
|
||||
|
||||
/// Unwraps this `LineColIterator`, returning the underlying iterator.
|
||||
pub fn into_inner(self) -> Iter { self.iter }
|
||||
}
|
||||
|
||||
impl<Iter: Iterator<Item=io::Result<u8>>> LineColIterator<Peekable<Iter>> {
|
||||
/// peeks at the next value
|
||||
pub fn peek(&mut self) -> Option<&io::Result<u8>> { self.iter.peek() }
|
||||
}
|
||||
|
||||
impl<Iter: Iterator<Item=io::Result<u8>>> Iterator for LineColIterator<Iter> {
|
||||
type Item = io::Result<u8>;
|
||||
fn next(&mut self) -> Option<io::Result<u8>> {
|
||||
|
||||
Reference in New Issue
Block a user