diff options
author | Joey Sacchini <joey@sacchini.net> | 2020-10-19 11:55:37 -0400 |
---|---|---|
committer | Joey Sacchini <joey@sacchini.net> | 2020-10-19 11:55:37 -0400 |
commit | 239a60fddab2694836f3117de429b9bf40256766 (patch) | |
tree | 007b927a3f3864639321cc988b0b0ad68f2c8662 /src/protocol.rs | |
parent | a2c1bcbf82a3ed7d76d464abab708f5472cfaa3f (diff) | |
download | mcproto-rs-239a60fddab2694836f3117de429b9bf40256766.tar.gz mcproto-rs-239a60fddab2694836f3117de429b9bf40256766.tar.bz2 mcproto-rs-239a60fddab2694836f3117de429b9bf40256766.zip |
allow no_std with alloc
Diffstat (limited to 'src/protocol.rs')
-rw-r--r-- | src/protocol.rs | 16 |
1 files changed, 8 insertions, 8 deletions
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<T: Serialize + Deserialize> 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::<usize>() % (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::<usize>() % (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<T> TestRandom for $name<T> where T: TestRandom + Debug + Clone + PartialEq, |