Skip to content

Commit

Permalink
support serialize for cases where we already support deserialize
Browse files Browse the repository at this point in the history
  • Loading branch information
GlenDC committed Sep 12, 2024
1 parent 856e789 commit f6fe967
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
6 changes: 3 additions & 3 deletions rama-cli/src/cmd/fp/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rama::{
},
Context,
};
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use serde_json::json;

type Html = rama::http::response::Html<String>;
Expand Down Expand Up @@ -123,7 +123,7 @@ pub(super) async fn get_report(mut ctx: Context<State>, req: Request) -> Result<
// endpoints: ACME
//------------------------------------------

#[derive(Debug, Deserialize)]
#[derive(Debug, Serialize, Deserialize)]
pub(super) struct AcmeChallengeParams {
token: String,
}
Expand All @@ -149,7 +149,7 @@ pub(super) async fn get_acme_challenge(
// endpoints: XHR
//------------------------------------------

#[derive(Deserialize)]
#[derive(Serialize, Deserialize)]
pub(super) struct APINumberParams {
number: usize,
}
Expand Down
14 changes: 13 additions & 1 deletion rama-dns/src/in_memory.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::DnsResolver;
use rama_net::address::Domain;
use rama_utils::macros::{error::static_str_error, impl_deref};
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use std::{
collections::HashMap,
net::{IpAddr, Ipv4Addr, Ipv6Addr},
Expand Down Expand Up @@ -29,6 +29,18 @@ impl<'de> Deserialize<'de> for DnsOverwrite {
}
}

impl Serialize for DnsOverwrite {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
match self.0.map.as_ref() {
Some(map) => map.serialize(serializer),
None => HashMap::<Domain, Vec<IpAddr>>::default().serialize(serializer),
}
}
}

#[derive(Debug, Clone)]
/// in-memory Dns that can be used as a simplistic cache,
/// or wrapped in [`DnsOverwrite`] to indicate dns overwrites.
Expand Down
14 changes: 13 additions & 1 deletion rama-net/src/asn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! See [`Asn`] and its methods for more information.
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use std::fmt;

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand Down Expand Up @@ -122,6 +122,18 @@ impl venndb::Any for Asn {
}
}

impl Serialize for Asn {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
match self.0 {
AsnData::Unspecified => 0u32.serialize(serializer),
AsnData::Specified(u) => u.serialize(serializer),
}
}
}

impl<'de> Deserialize<'de> for Asn {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
Expand Down
4 changes: 2 additions & 2 deletions rama-proxy/src/proxydb/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rama_core::error::{BoxError, ErrorContext, OpaqueError};
use rama_net::{asn::Asn, transport::TransportContext};
use rama_utils::str::NonEmptyString;
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use std::{fmt, future::Future};

#[cfg(feature = "live-update")]
Expand Down Expand Up @@ -57,7 +57,7 @@ impl From<NonEmptyString> for ProxyID {
}
}

#[derive(Debug, Default, Clone, Deserialize, PartialEq, Eq, Hash)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
/// Filter to select a specific kind of proxy.
///
/// If the `id` is specified the other fields are used
Expand Down

0 comments on commit f6fe967

Please sign in to comment.