Skip to content

Commit

Permalink
use cfg-if to take highest client-x feature
Browse files Browse the repository at this point in the history
  • Loading branch information
conorpp authored and nickray committed Jun 3, 2021
1 parent f748c49 commit c02ecc4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 69 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ resolver = "2"
# general
bitflags = "1.2"
# const-oid = "0.4.5"
cfg-if = "1.0"
embedded-hal = { version = "0.2.3", features = ["unproven"] }
flexiber = { git = "https://github.com/nickray/flexiber", branch = "main", features = ["derive", "heapless"] }
generic-array = "0.14.4"
Expand Down Expand Up @@ -60,7 +61,7 @@ entropy = "0.3.0"
# rand_core = { version = "0.5", features = ["getrandom"] }

[features]
default = ["default-mechanisms"]
default = ["default-mechanisms", "clients-1"]
verbose-tests = ["littlefs2/ll-assertions"]
verbose-lfs = ["littlefs2/ll-assertions", "littlefs2/ll-trace"]

Expand Down Expand Up @@ -104,6 +105,7 @@ tdes = ["des"]
totp = ["sha-1"]
trng = ["sha-1"]

clients-1 = []
clients-2 = []
clients-3 = []
clients-4 = []
Expand Down
119 changes: 51 additions & 68 deletions src/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,77 +5,60 @@ use crate::api::{Request, Reply};
use crate::error::Error;
use crate::types::ClientId;

#[cfg(not(any(
feature = "clients-2",
feature = "clients-3",
feature = "clients-4",
feature = "clients-5",
feature = "clients-6",
feature = "clients-7",
feature = "clients-8",
feature = "clients-9",
feature = "clients-10",
feature = "clients-11",
feature = "clients-12",
)))]
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>)
}

#[cfg(feature = "clients-2")]
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 2)
}

#[cfg(feature = "clients-3")]
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 3)
}

#[cfg(feature = "clients-4")]
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 4)
}

#[cfg(feature = "clients-5")]
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 5)
}

#[cfg(feature = "clients-6")]
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 6)
}

#[cfg(feature = "clients-7")]
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 7)
}

#[cfg(feature = "clients-8")]
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 8)
}

#[cfg(feature = "clients-9")]
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 9)
cfg_if::cfg_if! {

if #[cfg(feature = "clients-12")] {
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 12)
}
} else if #[cfg(feature = "clients-11")] {
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 11)
}
} else if #[cfg(feature = "clients-10")] {
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 10)
}
} else if #[cfg(feature = "clients-9")] {
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 9)
}
} else if #[cfg(feature = "clients-8")] {
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 8)
}
} else if #[cfg(feature = "clients-7")] {
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 7)
}
} else if #[cfg(feature = "clients-6")] {
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 6)
}
} else if #[cfg(feature = "clients-5")] {
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 5)
}
} else if #[cfg(feature = "clients-4")] {
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 4)
}
} else if #[cfg(feature = "clients-3")] {
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 3)
}
} else if #[cfg(feature = "clients-2")] {
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 2)
}
} else if #[cfg(feature = "clients-1")] {
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 1)
}
}
}

#[cfg(feature = "clients-10")]
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 10)
}

#[cfg(feature = "clients-11")]
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 11)
}

#[cfg(feature = "clients-12")]
interchange::interchange! {
TrussedInterchange: (Request, Result<Reply, Error>, 12)
}

// pub use interchange::TrussedInterchange;

Expand Down

0 comments on commit c02ecc4

Please sign in to comment.