Skip to content

Commit

Permalink
feat(pkarr): make serde not optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuhvi committed Dec 14, 2024
1 parent b205590 commit 95f106e
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 14 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions pkarr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ tokio = { version = "1.41.1", optional = true, default-features = false }
sha1_smol = { version = "1.0.1", optional = true }

# feat: serde dependencies
serde = { version = "1.0.215", features = ["derive"], optional = true }
serde = { version = "1.0.215", features = ["derive"] }

# feat: endpoints dependencies
futures-lite = { version = "2.5.0", default-features = false, features= ["std"], optional = true }
Expand All @@ -40,7 +40,7 @@ genawaiter = { version = "0.99.1", default-features = false, features = ["future
webpki-roots = { version = "0.26.7", optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
pubky-timestamp = { version = "0.2.0", default-features = false }
pubky-timestamp = { version = "0.2.0", features = ["full"] }

# feat: dht dependencies
mainline = { git = "https://github.com/pubky/mainline", branch="v5", optional = true }
Expand Down Expand Up @@ -86,9 +86,6 @@ dht = ["dep:mainline", "dep:flume"]
## Use [client::relay::Client]
relay = ["dep:reqwest", "dep:tokio", "dep:sha1_smol", "dep:flume"]

## Derive serde Serialize/Deserialize for PublicKey
serde = ["dep:serde", "pubky-timestamp/serde", "pubky-timestamp/httpdate"]

# Extra
## Use [crate::extra::lmdb-cache::LmdbCache]
lmdb-cache = ["dep:heed", "dep:byteorder", "dep:page_size"]
Expand All @@ -102,7 +99,7 @@ tls = ["rustls", "ed25519-dalek/pkcs8", "dep:webpki"]
reqwest-builder = ["tls", "reqwest-resolve"]

## Use all features
full = ["dht", "relay", "serde", "endpoints", "lmdb-cache", "reqwest-resolve", "tls", "reqwest-builder"]
full = ["dht", "relay", "endpoints", "lmdb-cache", "reqwest-resolve", "tls", "reqwest-builder"]

default = ["full"]

Expand Down
4 changes: 0 additions & 4 deletions pkarr/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use std::{
hash::Hash,
};

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

#[derive(Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -305,7 +304,6 @@ impl Debug for PublicKey {
}
}

#[cfg(feature = "serde")]
impl Serialize for PublicKey {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand All @@ -316,7 +314,6 @@ impl Serialize for PublicKey {
}
}

#[cfg(feature = "serde")]
impl<'de> Deserialize<'de> for PublicKey {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
Expand Down Expand Up @@ -510,7 +507,6 @@ mod tests {
assert_eq!(public_key.verifying_key().as_bytes(), &expected);
}

#[cfg(feature = "serde")]
#[test]
fn serde() {
let str = "yg4gxe7z1r7mr6orids9fh95y7gxhdsxjqi6nngsxxtakqaxr5no";
Expand Down
2 changes: 2 additions & 0 deletions pkarr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#![doc = document_features::document_features!()]
//!
// TODO: once we merge udp and relay clients, we should have a "client" feature

// Modules
#[cfg(any(target_arch = "wasm32", feature = "relay", feature = "dht"))]
pub mod client;
Expand Down
4 changes: 0 additions & 4 deletions pkarr/src/signed_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use std::{
net::{IpAddr, Ipv4Addr, Ipv6Addr},
};

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

use pubky_timestamp::Timestamp;
Expand Down Expand Up @@ -664,7 +663,6 @@ impl Display for SignedPacket {

// === Serialization ===

#[cfg(feature = "serde")]
impl Serialize for SignedPacket {
/// Serialize a [SignedPacket] for persistent storage.
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
Expand All @@ -675,7 +673,6 @@ impl Serialize for SignedPacket {
}
}

#[cfg(feature = "serde")]
impl<'de> Deserialize<'de> for SignedPacket {
/// Deserialize a [SignedPacket] from persistent storage.
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
Expand Down Expand Up @@ -1066,7 +1063,6 @@ mod tests {
);
}

#[cfg(feature = "serde")]
#[test]
fn serde() {
use postcard::{from_bytes, to_allocvec};
Expand Down

0 comments on commit 95f106e

Please sign in to comment.