Skip to content

Commit

Permalink
docs(primitives): document features in wrap_fixed_bytes-generated t…
Browse files Browse the repository at this point in the history
…ypes (#726)
  • Loading branch information
DaniPopes authored Sep 6, 2024
1 parent 24a7c52 commit dfa480e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/primitives/src/bits/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ macro_rules! impl_getrandom {
/// fails.
#[inline]
#[track_caller]
#[cfg_attr(docsrs, doc(cfg(feature = "getrandom")))]
pub fn random() -> Self {
Self($crate::FixedBytes::random())
}
Expand All @@ -447,6 +448,7 @@ macro_rules! impl_getrandom {
/// This function only propagates the error from the underlying call to
/// `getrandom_uninit`.
#[inline]
#[cfg_attr(docsrs, doc(cfg(feature = "getrandom")))]
pub fn try_random() -> $crate::private::Result<Self, $crate::private::getrandom::Error> {
$crate::FixedBytes::try_random().map(Self)
}
Expand All @@ -458,6 +460,7 @@ macro_rules! impl_getrandom {
/// Panics if the underlying call to `getrandom_uninit` fails.
#[inline]
#[track_caller]
#[cfg_attr(docsrs, doc(cfg(feature = "getrandom")))]
pub fn randomize(&mut self) {
self.try_randomize().unwrap()
}
Expand All @@ -469,6 +472,7 @@ macro_rules! impl_getrandom {
/// This function only propagates the error from the underlying call to
/// `getrandom_uninit`.
#[inline]
#[cfg_attr(docsrs, doc(cfg(feature = "getrandom")))]
pub fn try_randomize(
&mut self,
) -> $crate::private::Result<(), $crate::private::getrandom::Error> {
Expand All @@ -492,19 +496,22 @@ macro_rules! impl_rand {
/// Creates a new fixed byte array with the given random number generator.
#[inline]
#[doc(alias = "random_using")]
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
pub fn random_with<R: $crate::private::rand::Rng + ?Sized>(rng: &mut R) -> Self {
Self($crate::FixedBytes::random_with(rng))
}

/// Fills this fixed byte array with the given random number generator.
#[inline]
#[doc(alias = "randomize_using")]
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
pub fn randomize_with<R: $crate::private::rand::Rng + ?Sized>(&mut self, rng: &mut R) {
self.0.randomize_with(rng);
}
};

($t:ty) => {
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
impl $crate::private::rand::distributions::Distribution<$t>
for $crate::private::rand::distributions::Standard
{
Expand All @@ -528,13 +535,15 @@ macro_rules! impl_rand {
#[cfg(feature = "rlp")]
macro_rules! impl_rlp {
($t:ty, $n:literal) => {
#[cfg_attr(docsrs, doc(cfg(feature = "rlp")))]
impl $crate::private::alloy_rlp::Decodable for $t {
#[inline]
fn decode(buf: &mut &[u8]) -> $crate::private::alloy_rlp::Result<Self> {
$crate::private::alloy_rlp::Decodable::decode(buf).map(Self)
}
}

#[cfg_attr(docsrs, doc(cfg(feature = "rlp")))]
impl $crate::private::alloy_rlp::Encodable for $t {
#[inline]
fn length(&self) -> usize {
Expand Down Expand Up @@ -565,6 +574,7 @@ macro_rules! impl_rlp {
#[cfg(feature = "allocative")]
macro_rules! impl_allocative {
($t:ty) => {
#[cfg_attr(docsrs, doc(cfg(feature = "allocative")))]
impl $crate::private::allocative::Allocative for $t {
#[inline]
fn visit<'a, 'b: 'a>(&self, visitor: &'a mut $crate::private::allocative::Visitor<'b>) {
Expand All @@ -586,13 +596,15 @@ macro_rules! impl_allocative {
#[cfg(feature = "serde")]
macro_rules! impl_serde {
($t:ty) => {
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl $crate::private::serde::Serialize for $t {
#[inline]
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
$crate::private::serde::Serialize::serialize(&self.0, serializer)
}
}

#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<'de> $crate::private::serde::Deserialize<'de> for $t {
#[inline]
fn deserialize<D: $crate::private::serde::Deserializer<'de>>(
Expand All @@ -616,6 +628,7 @@ macro_rules! impl_serde {
#[cfg(feature = "arbitrary")]
macro_rules! impl_arbitrary {
($t:ty, $n:literal) => {
#[cfg_attr(docsrs, doc(cfg(feature = "arbitrary")))]
impl<'a> $crate::private::arbitrary::Arbitrary<'a> for $t {
#[inline]
fn arbitrary(u: &mut $crate::private::arbitrary::Unstructured<'a>) -> $crate::private::arbitrary::Result<Self> {
Expand All @@ -633,6 +646,7 @@ macro_rules! impl_arbitrary {
}
}

#[cfg_attr(docsrs, doc(cfg(feature = "arbitrary")))]
impl $crate::private::proptest::arbitrary::Arbitrary for $t {
type Parameters = <$crate::FixedBytes<$n> as $crate::private::proptest::arbitrary::Arbitrary>::Parameters;
type Strategy = $crate::private::proptest::strategy::Map<
Expand Down

0 comments on commit dfa480e

Please sign in to comment.