diff options
author | Joey Sacchini <joey@sacchini.net> | 2020-10-19 13:02:37 -0400 |
---|---|---|
committer | Joey Sacchini <joey@sacchini.net> | 2020-10-19 13:02:37 -0400 |
commit | b1630cb4decff257085ea1e55ba72c7dcfbdfd4b (patch) | |
tree | 26dd13da128f2be4f9bbcf379ce3ea457a9c1f94 /src/test_macros.rs | |
parent | 5817bb92e1e32ec767ad11abd49f2c7153703ea8 (diff) | |
download | mcproto-rs-b1630cb4decff257085ea1e55ba72c7dcfbdfd4b.tar.gz mcproto-rs-b1630cb4decff257085ea1e55ba72c7dcfbdfd4b.tar.bz2 mcproto-rs-b1630cb4decff257085ea1e55ba72c7dcfbdfd4b.zip |
make benchmarks an optional feature so we don't require nightly rust to use this crate
Diffstat (limited to 'src/test_macros.rs')
-rw-r--r-- | src/test_macros.rs | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/test_macros.rs b/src/test_macros.rs index ead3208..1ab1716 100644 --- a/src/test_macros.rs +++ b/src/test_macros.rs @@ -1,6 +1,3 @@ -use crate::{SerializeResult, Serializer}; -use alloc::vec::Vec; - #[cfg(all(test, feature = "std"))] #[macro_export] macro_rules! packet_test_cases { @@ -33,8 +30,9 @@ macro_rules! packet_test_cases { } } + #[cfg(feature = "bench")] #[bench] - fn $benchnams(b: &mut Bencher) { + fn $benchnams(b: &mut test::Bencher) { let packet = $pnam::$varnam($bodnam::test_gen_random()); let mut serializer = BenchSerializer::default(); packet @@ -51,8 +49,9 @@ macro_rules! packet_test_cases { }) } + #[cfg(feature = "bench")] #[bench] - fn $benchnamd(b: &mut Bencher) { + fn $benchnamd(b: &mut test::Bencher) { let packet = $pnam::$varnam($bodnam::test_gen_random()); let mut serializer = BytesSerializer::default(); packet @@ -72,21 +71,21 @@ macro_rules! packet_test_cases { }; } -#[cfg(all(test, feature = "std"))] +#[cfg(all(test, feature = "std", feature = "bench"))] #[derive(Clone, Debug, Default, PartialEq)] pub struct BenchSerializer { - data: Vec<u8>, + data: alloc::vec::Vec<u8>, } -#[cfg(all(test, feature = "std"))] -impl Serializer for BenchSerializer { - fn serialize_bytes(&mut self, data: &[u8]) -> SerializeResult { +#[cfg(all(test, feature = "std", feature = "bench"))] +impl crate::Serializer for BenchSerializer { + fn serialize_bytes(&mut self, data: &[u8]) -> crate::SerializeResult { self.data.extend_from_slice(data); Ok(()) } } -#[cfg(all(test, feature = "std"))] +#[cfg(all(test, feature = "std", feature = "bench"))] impl BenchSerializer { pub fn reset(&mut self) { self.data.clear(); |