Commit fa4ca09e authored by Ben Boeckel's avatar Ben Boeckel

serde: update for the 1.0 release

parent bc449ce5
......@@ -17,13 +17,13 @@ hyper = { version = "~0.10", default-features = false }
itertools = "~0.5"
log = "~0.3"
reqwest = "~0.4"
serde_derive = "~0.9"
serde_derive = "^1.0"
url = "^1.4"
chrono = { version = "=0.3.0", features = ["serde"] }
chrono = { version = "~0.3.1", features = ["serde"] }
error-chain = ">= 0.9, < 0.11"
serde = "~0.9"
serde_json = "~0.9"
serde = "~1.0"
serde_json = "^1.0"
[features]
strict = []
......@@ -10,7 +10,7 @@ use crates::itertools::Itertools;
use crates::reqwest::{Client, Method, RequestBuilder, Url};
use crates::serde::{Deserialize, Deserializer, Serializer};
use crates::serde::de::Error as SerdeError;
use crates::serde::de::Unexpected;
use crates::serde::de::{DeserializeOwned, Unexpected};
use crates::serde::ser::Serialize;
use crates::serde_json;
use crates::url::percent_encoding::{PATH_SEGMENT_ENCODE_SET, percent_encode};
......@@ -452,7 +452,7 @@ impl Gitlab {
/// Refactored code which talks to Gitlab and transforms error messages properly.
fn _comm<T>(&self, req: RequestBuilder) -> Result<T>
where T: Deserialize,
where T: DeserializeOwned,
{
let req = req.header(GitlabPrivateToken(self.token.to_string()));
let rsp = req.send().chain_err(|| ErrorKind::Communication)?;
......@@ -469,14 +469,16 @@ impl Gitlab {
}
/// Create a `GET` request to an API endpoint.
fn _get<T: Deserialize>(&self, url: &str) -> Result<T> {
fn _get<T>(&self, url: &str) -> Result<T>
where T: DeserializeOwned,
{
let param: &[(&str, &str)] = &[];
self._get_with_param(url, param)
}
/// Create a `GET` request to an API endpoint with query parameters.
fn _get_with_param<T, I, K, V>(&self, url: &str, param: I) -> Result<T>
where T: Deserialize,
where T: DeserializeOwned,
I: IntoIterator,
I::Item: Borrow<(K, V)>,
K: AsRef<str>,
......@@ -488,14 +490,16 @@ impl Gitlab {
}
/// Create a `POST` request to an API endpoint.
fn _post<T: Deserialize>(&self, url: &str) -> Result<T> {
fn _post<T>(&self, url: &str) -> Result<T>
where T: DeserializeOwned,
{
let param: &[(&str, &str)] = &[];
self._post_with_param(url, param)
}
/// Create a `POST` request to an API endpoint with query parameters.
fn _post_with_param<T, U>(&self, url: &str, param: U) -> Result<T>
where T: Deserialize,
where T: DeserializeOwned,
U: Serialize,
{
let full_url = self._mk_url(url)?;
......@@ -504,14 +508,16 @@ impl Gitlab {
}
/// Create a `PUT` request to an API endpoint.
fn _put<T: Deserialize>(&self, url: &str) -> Result<T> {
fn _put<T>(&self, url: &str) -> Result<T>
where T: DeserializeOwned,
{
let param: &[(&str, &str)] = &[];
self._put_with_param(url, param)
}
/// Create a `PUT` request to an API endpoint with query parameters.
fn _put_with_param<T, U>(&self, url: &str, param: U) -> Result<T>
where T: Deserialize,
where T: DeserializeOwned,
U: Serialize,
{
let full_url = self._mk_url(url)?;
......@@ -520,14 +526,16 @@ impl Gitlab {
}
/// Handle paginated queries. Returns all results.
fn _get_paged<T: Deserialize>(&self, url: &str) -> Result<Vec<T>> {
fn _get_paged<T>(&self, url: &str) -> Result<Vec<T>>
where T: DeserializeOwned,
{
let param: &[(&str, &str)] = &[];
self._get_paged_with_param(url, param)
}
/// Handle paginated queries with query parameters. Returns all results.
fn _get_paged_with_param<T, I, K, V>(&self, url: &str, param: I) -> Result<Vec<T>>
where T: Deserialize,
where T: DeserializeOwned,
I: IntoIterator,
I::Item: Borrow<(K, V)>,
K: AsRef<str>,
......
......@@ -29,8 +29,10 @@ pub enum GitlabHook {
Web(WebHook),
}
impl Deserialize for GitlabHook {
fn deserialize<D: Deserializer>(deserializer: D) -> Result<Self, D::Error> {
impl<'de> Deserialize<'de> for GitlabHook {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,
{
let val = <Value as Deserialize>::deserialize(deserializer)?;
// Look for `object_kind` first because some web hooks also have `event_name` which would
......
......@@ -54,9 +54,9 @@ macro_rules! enum_serialize {
}
}
impl Deserialize for $name {
impl<'de> Deserialize<'de> for $name {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where D: Deserializer,
where D: Deserializer<'de>,
{
let val = String::deserialize(deserializer)?;
......
......@@ -381,8 +381,10 @@ pub enum SystemHook {
Push(PushSystemHook),
}
impl Deserialize for SystemHook {
fn deserialize<D: Deserializer>(deserializer: D) -> Result<Self, D::Error> {
impl<'de> Deserialize<'de> for SystemHook {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,
{
let val = <Value as Deserialize>::deserialize(deserializer)?;
let event_name = match val.pointer("/event_name") {
......
......@@ -7,14 +7,14 @@
// except according to those terms.
use crates::chrono::{TimeZone, UTC};
use crates::serde::Deserialize;
use crates::serde::de::DeserializeOwned;
use crates::serde_json::from_reader;
use types::*;
use std::fs::File;
fn read_test_file<T: Deserialize>(name: &str) -> T {
fn read_test_file<T: DeserializeOwned>(name: &str) -> T {
let fin = File::open(format!(concat!(env!("CARGO_MANIFEST_DIR"), "/data/{}.json"), name))
.unwrap();
......
......@@ -16,7 +16,7 @@
use crates::chrono::{DateTime, NaiveDate, UTC};
use crates::serde::{Deserialize, Deserializer, Serialize, Serializer};
use crates::serde::de::{Error, Unexpected};
use crates::serde::de::{DeserializeOwned, Error, Unexpected};
use crates::serde_json::{self, Value};
use std::fmt::{self, Display, Formatter};
......@@ -74,8 +74,8 @@ pub struct UserBasic {
/// This is used to allow (direct) user queries to return the right information because
/// administrator users receive additional information for all user queries versus
/// non-administrator users.
pub trait UserResult: Deserialize {}
impl<T: Deserialize + Into<UserBasic>> UserResult for T {}
pub trait UserResult: DeserializeOwned {}
impl<T: DeserializeOwned + Into<UserBasic>> UserResult for T {}
#[cfg_attr(feature="strict", serde(deny_unknown_fields))]
#[derive(Serialize, Deserialize, Debug, Clone)]
......@@ -1171,8 +1171,10 @@ impl Serialize for IssueReference {
}
}
impl Deserialize for IssueReference {
fn deserialize<D: Deserializer>(deserializer: D) -> Result<Self, D::Error> {
impl<'de> Deserialize<'de> for IssueReference {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,
{
let val = <Value as Deserialize>::deserialize(deserializer)?;
serde_json::from_value::<Issue>(val.clone())
......
......@@ -34,8 +34,10 @@ impl Serialize for HookDate {
}
}
impl Deserialize for HookDate {
fn deserialize<D: Deserializer>(deserializer: D) -> Result<Self, D::Error> {
impl<'de> Deserialize<'de> for HookDate {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,
{
let val = String::deserialize(deserializer)?;
UTC.datetime_from_str(&val, "%Y-%m-%d %H:%M:%S UTC")
......@@ -733,8 +735,10 @@ pub enum WebHook {
WikiPage(WikiPageHook),
}
impl Deserialize for WebHook {
fn deserialize<D: Deserializer>(deserializer: D) -> Result<Self, D::Error> {
impl<'de> Deserialize<'de> for WebHook {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,
{
let val = <Value as Deserialize>::deserialize(deserializer)?;
let object_kind = match val.pointer("/object_kind") {
......
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