diff --git a/units/src/time.rs b/units/src/time.rs index bd0cdb556..2534763b9 100644 --- a/units/src/time.rs +++ b/units/src/time.rs @@ -9,34 +9,39 @@ #[cfg(feature = "arbitrary")] use arbitrary::{Arbitrary, Unstructured}; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; -/// A Bitcoin block timestamp. -/// -/// > Each block contains a Unix time timestamp. In addition to serving as a source of variation for -/// > the block hash, they also make it more difficult for an adversary to manipulate the block chain. -/// > -/// > A timestamp is accepted as valid if it is greater than the median timestamp of previous 11 -/// > blocks, and less than the network-adjusted time + 2 hours. "Network-adjusted time" is the -/// > median of the timestamps returned by all nodes connected to you. As a result block timestamps -/// > are not exactly accurate, and they do not need to be. Block times are accurate only to within -/// > an hour or two. -/// -/// ref: -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct BlockTime(u32); +mod encapsulate { + #[cfg(feature = "serde")] + use serde::{Deserialize, Serialize}; -impl BlockTime { - /// Constructs a new [`BlockTime`] from an unsigned 32 bit integer value. - #[inline] - pub const fn from_u32(t: u32) -> Self { BlockTime(t) } + /// A Bitcoin block timestamp. + /// + /// > Each block contains a Unix time timestamp. In addition to serving as a source of variation for + /// > the block hash, they also make it more difficult for an adversary to manipulate the block chain. + /// > + /// > A timestamp is accepted as valid if it is greater than the median timestamp of previous 11 + /// > blocks, and less than the network-adjusted time + 2 hours. "Network-adjusted time" is the + /// > median of the timestamps returned by all nodes connected to you. As a result block timestamps + /// > are not exactly accurate, and they do not need to be. Block times are accurate only to within + /// > an hour or two. + /// + /// ref: + #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] + #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] + pub struct BlockTime(u32); - /// Returns the inner `u32` value. - #[inline] - pub const fn to_u32(self) -> u32 { self.0 } + impl BlockTime { + /// Constructs a new [`BlockTime`] from an unsigned 32 bit integer value. + #[inline] + pub const fn from_u32(t: u32) -> Self { BlockTime(t) } + + /// Returns the inner `u32` value. + #[inline] + pub const fn to_u32(self) -> u32 { self.0 } + } } +#[doc(inline)] +pub use encapsulate::BlockTime; impl From for BlockTime { #[inline]