forked from private-attribution/ipa
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set SO_KEEPALIVE for IPA connections
See private-attribution#758 for details
- Loading branch information
Showing
5 changed files
with
121 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//! Serialization helpers for Serde | ||
#[cfg(feature = "web-app")] | ||
pub mod uri { | ||
use hyper::Uri; | ||
use serde::{de::Error, Deserialize, Deserializer}; | ||
|
||
/// # Errors | ||
/// if deserializing from string fails, or if string is not a [`Uri`] | ||
pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Uri, D::Error> { | ||
let s: String = Deserialize::deserialize(deserializer)?; | ||
s.parse().map_err(D::Error::custom) | ||
} | ||
} | ||
|
||
pub mod duration { | ||
use std::time::Duration; | ||
|
||
pub fn to_secs<'a, I, S>(d: I, s: S) -> Result<S::Ok, S::Error> | ||
where | ||
Option<&'a Duration>: From<I>, | ||
S: serde::Serializer, | ||
{ | ||
let d = d.into(); | ||
match d { | ||
Some(v) => s.serialize_f64(v.as_secs_f64()), | ||
None => s.serialize_none(), | ||
} | ||
} | ||
|
||
pub fn from_secs<'de, D: serde::Deserializer<'de>>(d: D) -> Result<Duration, D::Error> { | ||
let secs = serde::Deserialize::deserialize(d)?; | ||
Ok(Duration::from_secs_f64(secs)) | ||
} | ||
|
||
pub fn from_secs_optional<'de, D: serde::Deserializer<'de>>( | ||
d: D, | ||
) -> Result<Option<Duration>, D::Error> { | ||
let secs: Option<f64> = serde::Deserialize::deserialize(d)?; | ||
Ok(secs.map(Duration::from_secs_f64)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1 @@ | ||
use hyper::Uri; | ||
use serde::{de::Error, Deserialize, Deserializer, Serializer}; | ||
|
||
/// # Errors | ||
/// if serializing to string fails | ||
pub fn serialize<S: Serializer>(uri: &Uri, serializer: S) -> Result<S::Ok, S::Error> { | ||
serializer.serialize_str(&uri.to_string()) | ||
} | ||
|
||
/// # Errors | ||
/// if deserializing from string fails, or if string is not a [`Uri`] | ||
pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Uri, D::Error> { | ||
let s: String = Deserialize::deserialize(deserializer)?; | ||
s.parse().map_err(D::Error::custom) | ||
} |