Skip to content

Commit

Permalink
refactor: remove cfg_if from channels_serdes
Browse files Browse the repository at this point in the history
  • Loading branch information
threadexio committed Mar 18, 2024
1 parent 4588d25 commit 3a82193
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 29 deletions.
2 changes: 0 additions & 2 deletions channels-serdes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ json = ["dep:serde", "dep:serde_json"]
borsh = ["dep:borsh"]

[dependencies]
cfg-if = "1.0"

bincode = { version = "1.3", optional = true }
ciborium = { version = "0.2", optional = true }
borsh = { version = "1.3", optional = true }
Expand Down
38 changes: 11 additions & 27 deletions channels-serdes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,16 @@ pub trait Deserializer<T> {
) -> Result<T, Self::Error>;
}

use cfg_if::cfg_if;

cfg_if! {
if #[cfg(feature = "bincode")] {
mod bincode;
pub use self::bincode::Bincode;
}
}

cfg_if! {
if #[cfg(feature = "cbor")] {
mod cbor;
pub use self::cbor::Cbor;
}
macro_rules! serde_impl {
($module:ident :: $impl:ident if $feature:literal) => {
#[cfg(feature = $feature)]
mod $module;
#[cfg(feature = $feature)]
pub use self::$module::$impl;
};
}

cfg_if! {
if #[cfg(feature = "json")] {
mod json;
pub use self::json::Json;
}
}

cfg_if! {
if #[cfg(feature = "borsh")] {
mod borsh;
pub use self::borsh::Borsh;
}
}
serde_impl! { bincode::Bincode if "bincode" }
serde_impl! { cbor::Cbor if "cbor" }
serde_impl! { json::Json if "json" }
serde_impl! { borsh::Borsh if "borsh" }

0 comments on commit 3a82193

Please sign in to comment.