devela 0.27.0

A development layer of coherence.
Documentation
// devela::examples::data::bitfield
//
//! Shows how to use the [`bitfield!`] declarative macro.
//

use devela::bitfield;

bitfield! {
    (extra)

    /// An example created with [`bitfield!`],
    /// with public extra methods but no custom fields.
    ///
    /// ```
    /// use devela::bitfield;
    ///
    /// bitfield! {
    ///     (extra)
    ///
    ///     /// An example created with [`bitfield!`],
    ///     /// with public extra methods but no custom fields.
    ///     pub struct ExampleBitfieldExtra(u8) {}
    /// }
    /// ```
    pub struct ExampleBitfieldExtra(u8) {}
}

bitfield! {
    (custom)

    /// An example created with [`bitfield!`],
    /// with public custom fields but no extra methods.
    ///
    /// ```
    /// use devela::bitfield;
    ///
    /// bitfield! {
    ///     (custom)
    ///
    ///     /// An example created with [`bitfield!`],
    ///     /// with public custom fields but no extra methods.
    ///     pub struct ExampleBitfieldCustom(u8) {
    ///         /// Documentation for the first field.
    ///         FLAG1: 0;
    ///         /// Documentation for the second field.
    ///         FLAG2: 1;
    ///         MASK: 0, 1;
    ///     }
    /// }
    ///
    /// let mut b = ExampleBitfieldCustom::with_field_mask();
    /// assert![b.is_field_mask()];
    /// assert![b.is_field_flag1()];
    /// assert![b.is_field_flag2()];
    /// let _c = b.unset_field_flag1();
    /// ```
    pub struct ExampleBitfieldCustom(u8) {
        /// Documentation for the first field.
        FLAG1: 0;
        /// Documentation for the second field.
        FLAG2: 1;
        #[allow(missing_docs)]
        MASK0: 0, 1;
    }
}

bitfield! {
    /// An example created with [`bitfield!`], everything public.
    ///
    /// ```
    /// use devela::bitfield;
    ///
    /// bitfield! {
    ///     /// An example created with [`bitfield!`], everything public.
    ///     pub struct ExampleBitfield(u8) {
    ///         /// Documentation for the first field.
    ///         FLAG1: 0;
    ///         /// Documentation for the second field.
    ///         FLAG2: 1;
    ///         MASK: 0, 1;
    ///     }
    /// }
    ///
    /// let mut b = ExampleBitfield::with_field_mask();
    /// assert![b.is_field_mask()];
    /// assert![b.is_field_flag1()];
    /// assert![b.is_field_flag2()];
    /// let _c = b.unset_field_flag1();
    /// ```
    pub struct ExampleBitfield(u8) {
        /// Documentation for the first field.
        FLAG1: 0;
        /// Documentation for the second field.
        FLAG2: 1;
        #[allow(missing_docs)]
        MASK0: 0, 1;
    }
}

fn main() {}