From 239a60fddab2694836f3117de429b9bf40256766 Mon Sep 17 00:00:00 2001 From: Joey Sacchini Date: Mon, 19 Oct 2020 11:55:37 -0400 Subject: allow no_std with alloc --- src/protocol.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/protocol.rs') diff --git a/src/protocol.rs b/src/protocol.rs index 5f2ea67..9e7307e 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -1,5 +1,5 @@ use crate::{Deserialize, DeserializeErr, Serialize}; -use std::fmt; +use alloc::{string::String, fmt, vec::Vec}; #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] pub struct ProtocolSpec { @@ -73,7 +73,7 @@ pub trait ProtocolType: Serialize + Deserialize {} impl ProtocolType for T {} -#[cfg(test)] +#[cfg(all(test, feature = "std"))] pub trait TestRandom { fn test_gen_random() -> Self; } @@ -115,7 +115,7 @@ macro_rules! __protocol_body_def_helper { } } - #[cfg(test)] + #[cfg(all(test, feature = "std"))] impl TestRandom for $bodyt { fn test_gen_random() -> Self { Self::default() @@ -147,7 +147,7 @@ macro_rules! __protocol_body_def_helper { } } - #[cfg(test)] + #[cfg(all(test, feature = "std"))] impl TestRandom for $bodyt { fn test_gen_random() -> Self { Self{ $($fname: <$ftyp>::test_gen_random()),+ } @@ -433,7 +433,7 @@ macro_rules! proto_enum_with_type { } } - #[cfg(test)] + #[cfg(all(test, feature = "std"))] impl TestRandom for $typname { fn test_gen_random() -> Self { let mut idx: usize = (rand::random::() % (count_num!($($bval),+))) + 1; @@ -537,7 +537,7 @@ macro_rules! proto_str_enum { } } - #[cfg(test)] + #[cfg(all(test, feature = "std"))] impl TestRandom for $typname { fn test_gen_random() -> Self { let mut idx: usize = (rand::random::() % (count_num!($($nam),+))) + 1; @@ -601,7 +601,7 @@ macro_rules! proto_byte_flag { } } - #[cfg(test)] + #[cfg(all(test, feature = "std"))] impl TestRandom for $typname { fn test_gen_random() -> Self { let mut out = <$typname>::default(); @@ -722,7 +722,7 @@ macro_rules! counted_array_type { } } - #[cfg(test)] + #[cfg(all(test, feature = "std"))] impl TestRandom for $name where T: TestRandom + Debug + Clone + PartialEq, -- cgit