fix: made rand optional

This commit is contained in:
Strix 2023-12-06 23:30:09 +01:00
parent 49424a91f5
commit 9718b1f92c
No known key found for this signature in database
GPG key ID: 5F35B3B8537287A7
3 changed files with 12 additions and 4 deletions

View file

@ -7,4 +7,11 @@ edition = "2021"
[dependencies]
crc32fast = "1.3.2"
rand = "0.8.5"
[dependencies.rand]
version = "0.8.5"
optional = true
[features]
default = ["random"]
random = ["rand"]

View file

@ -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)
}

View file

@ -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)
}