From 337ddff3081351f71ea74a9b45e14744366b06a0 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Sat, 22 Jul 2023 11:10:26 -0700 Subject: [PATCH] docs fixy-wixy --- bitfield/src/bitfield.rs | 11 +++++++---- bitfield/src/from_bits.rs | 10 ++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/bitfield/src/bitfield.rs b/bitfield/src/bitfield.rs index bda0154c..b568b8b7 100644 --- a/bitfield/src/bitfield.rs +++ b/bitfield/src/bitfield.rs @@ -107,7 +107,7 @@ /// /// Bitfields may also contain typed values, as long as those values implement /// the [`FromBits`] trait. [`FromBits`] may be manually implemented, or -/// generated automatically for `enum` types using the [`enum_from_bits!] macro: +/// generated automatically for `enum` types using the [`enum_from_bits!`] macro: /// /// ``` /// use mycelium_bitfield::{bitfield, enum_from_bits, FromBits}; @@ -141,9 +141,12 @@ /// } /// } /// -/// Alternatively, the `enum_from_bits!` macro can be used to -/// automatically generate a `FromBits` implementation for an -/// enum type: +/// // Alternatively, the `enum_from_bits!` macro can be used to +/// // automatically generate a `FromBits` implementation for an +/// // enum type. +/// // +/// // The macro will generate very similar code to the example +/// // manual implementation above. /// enum_from_bits! { /// #[derive(Debug, Eq, PartialEq)] /// pub enum MyGeneratedEnum { diff --git a/bitfield/src/from_bits.rs b/bitfield/src/from_bits.rs index 92a80d5d..32d77da0 100644 --- a/bitfield/src/from_bits.rs +++ b/bitfield/src/from_bits.rs @@ -1,6 +1,15 @@ use core::{convert::Infallible, fmt}; /// Trait implemented by values which can be converted to and from raw bits. +/// +/// This trait is [implemented by default] for all signed and unsigned integer +/// types, as well as for `bool`s. It can be implemented manually for any +/// user-defined type which has a well-defined bit-pattern representation. For +/// `enum` types with unsigned integer `repr`s, it may also be implemented +/// automatically using the [`enum_from_bits!`] macro. +/// +/// [implemented by default]: #foreign-impls +/// [`enum_from_bits!`]: crate::enum_from_bits! pub trait FromBits: Sized { /// The error type returned by [`Self::try_from_bits`] when an invalid bit /// pattern is encountered. @@ -99,6 +108,7 @@ pub trait FromBits: Sized { /// Wont = 0b10, /// Work = 0b11, /// } +/// } /// ``` /// /// [^1]: **Why Not `#[derive(FromBits)]`?** Some readers may be curious about why