fix: made rand optional
This commit is contained in:
parent
49424a91f5
commit
9718b1f92c
3 changed files with 12 additions and 4 deletions
|
@ -7,4 +7,11 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
crc32fast = "1.3.2"
|
crc32fast = "1.3.2"
|
||||||
rand = "0.8.5"
|
|
||||||
|
[dependencies.rand]
|
||||||
|
version = "0.8.5"
|
||||||
|
optional = true
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["random"]
|
||||||
|
random = ["rand"]
|
|
@ -1,5 +1,4 @@
|
||||||
use std::fmt::{Display, Formatter, LowerHex};
|
use std::fmt::{Display, Formatter, LowerHex};
|
||||||
use rand::random;
|
|
||||||
|
|
||||||
/// Helper struct for the identifiers used in `dest`, `src`, `packet_id` and `reply_to`.
|
/// Helper struct for the identifiers used in `dest`, `src`, `packet_id` and `reply_to`.
|
||||||
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
|
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
|
||||||
|
@ -8,12 +7,14 @@ pub struct Identifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Identifier {
|
impl Identifier {
|
||||||
|
#[cfg(feature = "random")]
|
||||||
pub fn random() -> Identifier {
|
pub fn random() -> Identifier {
|
||||||
Identifier::from(random::<u32>())
|
Identifier::from(rand::random::<u32>())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Identifier {
|
impl Default for Identifier {
|
||||||
|
/// Zero!
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Identifier::from(0x00000000)
|
Identifier::from(0x00000000)
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ impl Default for Packet {
|
||||||
dest: Identifier::from(0xFFFFFFFF),
|
dest: Identifier::from(0xFFFFFFFF),
|
||||||
src: Identifier::from(0),
|
src: Identifier::from(0),
|
||||||
command: 0x00,
|
command: 0x00,
|
||||||
packet_id: Identifier::random(),
|
packet_id: Identifier::default(),
|
||||||
reply_to: Identifier::default(),
|
reply_to: Identifier::default(),
|
||||||
data: PacketData::NodeManagement(crate::commands::node_management::NodeManagementCommand::Ping)
|
data: PacketData::NodeManagement(crate::commands::node_management::NodeManagementCommand::Ping)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue