diff --git a/domo_proto/Cargo.toml b/domo_proto/Cargo.toml index 46f1840..c10654f 100644 --- a/domo_proto/Cargo.toml +++ b/domo_proto/Cargo.toml @@ -7,4 +7,11 @@ edition = "2021" [dependencies] crc32fast = "1.3.2" -rand = "0.8.5" \ No newline at end of file + +[dependencies.rand] +version = "0.8.5" +optional = true + +[features] +default = ["random"] +random = ["rand"] \ No newline at end of file diff --git a/domo_proto/src/identifier.rs b/domo_proto/src/identifier.rs index 6be5ba1..cb23e9f 100644 --- a/domo_proto/src/identifier.rs +++ b/domo_proto/src/identifier.rs @@ -1,5 +1,4 @@ use std::fmt::{Display, Formatter, LowerHex}; -use rand::random; /// Helper struct for the identifiers used in `dest`, `src`, `packet_id` and `reply_to`. #[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)] @@ -8,12 +7,14 @@ pub struct Identifier { } impl Identifier { + #[cfg(feature = "random")] pub fn random() -> Identifier { - Identifier::from(random::<u32>()) + Identifier::from(rand::random::<u32>()) } } impl Default for Identifier { + /// Zero! fn default() -> Self { Identifier::from(0x00000000) } diff --git a/domo_proto/src/packet/mod.rs b/domo_proto/src/packet/mod.rs index 2a39421..6fa29b9 100644 --- a/domo_proto/src/packet/mod.rs +++ b/domo_proto/src/packet/mod.rs @@ -38,7 +38,7 @@ impl Default for Packet { dest: Identifier::from(0xFFFFFFFF), src: Identifier::from(0), command: 0x00, - packet_id: Identifier::random(), + packet_id: Identifier::default(), reply_to: Identifier::default(), data: PacketData::NodeManagement(crate::commands::node_management::NodeManagementCommand::Ping) }