From 9718b1f92c9f2dbfd6de2c80006adeac731b3055 Mon Sep 17 00:00:00 2001 From: Raine Date: Wed, 6 Dec 2023 23:30:09 +0100 Subject: [PATCH] fix: made rand optional --- domo_proto/Cargo.toml | 9 ++++++++- domo_proto/src/identifier.rs | 5 +++-- domo_proto/src/packet/mod.rs | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) 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::()) + Identifier::from(rand::random::()) } } 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) }