Commit d6488d55 authored by Ben Boeckel's avatar Ben Boeckel

cargo: update to serde 0.9 and serde_derive

parent 781dbd6c
......@@ -9,17 +9,14 @@ Gitlab API client.
repository = "https://gitlab.kitware.com/utils/rust-gitlab"
documentation = "https://docs.rs/gitlab/~0.1"
readme = "README.md"
build = "build.rs"
[build-dependencies]
serde_codegen = "~0.8"
[dependencies]
chrono = { version = "~0.2", features = ["serde"] }
chrono = { version = "~0.3", features = ["serde"] }
error-chain = "~0.7"
hyper = { version = "~0.9", default-features = false }
log = "~0.3"
reqwest = "~0.2"
serde = "~0.8"
serde_json = "~0.8"
serde = "~0.9"
serde_derive = "~0.9"
serde_json = "~0.9"
url = "~1.2"
// Copyright 2016 Kitware, Inc.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate serde_codegen;
use std::env;
use std::fs;
use std::path::Path;
pub fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let paths = [
"systemhooks",
"types",
"webhooks",
];
for path in &paths {
let src = format!("src/{}.rs.in", path);
let dst = format!("{}.rs", path);
let src_path = Path::new(&src);
let dst_path = Path::new(&out_dir).join(&dst);
fs::create_dir_all(dst_path.parent().unwrap()).unwrap();
serde_codegen::expand(&src_path, &dst_path).unwrap();
}
}
......@@ -10,8 +10,10 @@ extern crate reqwest;
use self::reqwest::{Client, RequestBuilder, Url};
extern crate serde;
use self::serde::{Deserialize, Deserializer, Serialize, Serializer};
use self::serde::{Deserialize, Deserializer, Serializer};
use self::serde::de::Error as SerdeError;
use self::serde::de::Unexpected;
use self::serde::ser::Serialize;
extern crate serde_json;
......
......@@ -15,7 +15,7 @@
extern crate serde;
use self::serde::{Deserialize, Deserializer};
use self::serde::de::Error;
use self::serde::de::{Error, Unexpected};
extern crate serde_json;
use self::serde_json::Value;
......@@ -33,8 +33,8 @@ pub enum GitlabHook {
}
impl Deserialize for GitlabHook {
fn deserialize<D: Deserializer>(deserializer: &mut D) -> Result<Self, D::Error> {
let val = Value::deserialize(deserializer)?;
fn deserialize<D: Deserializer>(deserializer: D) -> Result<Self, D::Error> {
let val = <Value as Deserialize>::deserialize(deserializer)?;
// Look for `object_kind` first because some web hooks also have `event_name` which would
// cause a false match here.
......@@ -46,6 +46,9 @@ impl Deserialize for GitlabHook {
return Err(D::Error::missing_field("either object_kind or event_name"));
};
hook_res.map_err(|err| D::Error::invalid_value(&format!("{:?}", err)))
hook_res.map_err(|err| {
D::Error::invalid_value(Unexpected::Other("gitlab hook"),
&format!("{:?}", err).as_str())
})
}
}
......@@ -19,6 +19,9 @@ extern crate hyper;
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde_derive;
mod error;
#[macro_use]
mod macros;
......
......@@ -47,20 +47,25 @@ macro_rules! enum_serialize {
}
impl Serialize for $name {
fn serialize<S: Serializer>(&self, serializer: &mut S) -> ::std::result::Result<(), S::Error> {
fn serialize<S>(&self, serializer: S) -> ::std::result::Result<S::Ok, S::Error>
where S: Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl Deserialize for $name {
fn deserialize<D: Deserializer>(deserializer: &mut D) -> ::std::result::Result<Self, D::Error> {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where D: Deserializer,
{
let val = String::deserialize(deserializer)?;
match val.as_str() {
$( $str => Ok($name::$value), )*
v => {
error!(target: "gitlab", concat!("unknown ", $desc, " from gitlab: {}"), v);
Err(D::Error::invalid_value(concat!("invalid ", $desc)))
Err(D::Error::invalid_value(Unexpected::Other("enumeration value"),
&concat!("invalid ", $desc)))
},
}
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment