diff --git a/Cargo.toml b/Cargo.toml index e311c3d..7632cdb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,11 +16,16 @@ categories = ["web-programming::http-client", "web-programming"] # https://crat all-features = true rustdoc-args = ["--cfg", "docsrs"] +[features] +serde = ["dep:serde" , "dep:serde_derive"] + [dependencies] bytes = "1.0.1" cookie_store = "^0.20" reqwest = { version = "^0.11", default-features = false, features = ["cookies"] } url = "2.2.2" +serde = {version = "1.0.147", optional = true} +serde_derive = {version = "1.0.147" , optional = true } [dev-dependencies] tokio-test = "0.4.1" diff --git a/src/lib.rs b/src/lib.rs index f194690..6b0fae5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -87,6 +87,8 @@ use std::{ use bytes::Bytes; pub use cookie_store::{CookieStore, RawCookie, RawCookieParseError}; use reqwest::header::HeaderValue; +#[cfg(feature = "serde")] +use serde_derive::{Deserialize, Serialize}; use url; fn set_cookies( @@ -121,6 +123,7 @@ fn cookies(cookie_store: &CookieStore, url: &url::Url) -> Option { /// A [`cookie_store::CookieStore`] wrapped internally by a [`std::sync::Mutex`], suitable for use in /// async/concurrent contexts. #[derive(Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct CookieStoreMutex(Mutex); impl Default for CookieStoreMutex { @@ -164,6 +167,7 @@ impl reqwest::cookie::CookieStore for CookieStoreMutex { /// A [`cookie_store::CookieStore`] wrapped internally by a [`std::sync::RwLock`], suitable for use in /// async/concurrent contexts. #[derive(Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct CookieStoreRwLock(RwLock); impl Default for CookieStoreRwLock {