From 345d1d5474ad0e90e3ddda4378061e63178f75bf Mon Sep 17 00:00:00 2001 From: orzogc Date: Thu, 24 Jun 2021 14:25:04 +0800 Subject: [PATCH] Derive some useful traits (#28) --- pretend-isahc/src/lib.rs | 1 + pretend-reqwest/src/blocking.rs | 2 +- pretend-reqwest/src/lib.rs | 2 +- pretend/src/lib.rs | 6 ++++-- pretend/src/resolver.rs | 2 ++ 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pretend-isahc/src/lib.rs b/pretend-isahc/src/lib.rs index 41f6aae..3510830 100644 --- a/pretend-isahc/src/lib.rs +++ b/pretend-isahc/src/lib.rs @@ -12,6 +12,7 @@ use pretend::{Error, HeaderMap, Response, Result, Url}; use std::mem; /// `ishac` based `pretend` client +#[derive(Clone, Debug)] pub struct Client { client: HttpClient, } diff --git a/pretend-reqwest/src/blocking.rs b/pretend-reqwest/src/blocking.rs index 2c38642..f5f6de8 100644 --- a/pretend-reqwest/src/blocking.rs +++ b/pretend-reqwest/src/blocking.rs @@ -4,7 +4,7 @@ use reqwest::blocking::Client; use std::mem; /// `reqwest` based `pretend` blocking client -#[derive(Default)] +#[derive(Clone, Debug, Default)] pub struct BlockingClient { client: Client, } diff --git a/pretend-reqwest/src/lib.rs b/pretend-reqwest/src/lib.rs index 84eb601..93ad5b9 100644 --- a/pretend-reqwest/src/lib.rs +++ b/pretend-reqwest/src/lib.rs @@ -19,7 +19,7 @@ use reqwest::Client as RClient; use std::mem; /// `reqwest` based `pretend` client -#[derive(Default)] +#[derive(Clone, Debug, Default)] pub struct Client { client: RClient, } diff --git a/pretend/src/lib.rs b/pretend/src/lib.rs index 3c12d70..6062f2c 100644 --- a/pretend/src/lib.rs +++ b/pretend/src/lib.rs @@ -285,6 +285,7 @@ use crate::resolver::{InvalidUrlResolver, ResolveUrl, UrlResolver}; use serde::de::DeserializeOwned; /// Response type +#[derive(Clone, Debug, Eq, PartialEq)] pub struct Response { status: StatusCode, headers: HeaderMap, @@ -334,6 +335,7 @@ impl Response { /// be implemented by this struct. /// /// See crate level documentation for more information +#[derive(Clone, Debug)] pub struct Pretend where R: ResolveUrl, @@ -393,7 +395,7 @@ impl Pretend { /// /// This wrapper type indicates that a method should return /// a JSON-serialized body. -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Debug, Clone, Eq, PartialEq, Hash)] pub struct Json where T: DeserializeOwned, @@ -428,7 +430,7 @@ where /// When the HTTP request is successful, the `Ok` variant will /// be returned, and when the HTTP request has failed, the /// `Err` variant will be returned. -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Debug, Clone, Eq, PartialEq, Hash)] pub enum JsonResult where T: DeserializeOwned, diff --git a/pretend/src/resolver.rs b/pretend/src/resolver.rs index 09c0ace..32c9d65 100644 --- a/pretend/src/resolver.rs +++ b/pretend/src/resolver.rs @@ -24,6 +24,7 @@ pub trait ResolveUrl { /// Default URL resolver /// /// This resolver appends the path to a base URL. +#[derive(Clone, Debug)] pub struct UrlResolver { base: Url, } @@ -48,6 +49,7 @@ impl ResolveUrl for UrlResolver { /// /// `[Pretend::with_url]` or `[Pretend::with_url_resolver]` should be used to /// set a valid URL resolver. +#[derive(Clone, Copy, Debug)] pub struct InvalidUrlResolver; impl ResolveUrl for InvalidUrlResolver {