Skip to content

add is_set / is_clear methods #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,23 @@ pub fn fields(
},
);
}

if f.width == 1 {
enum_items.push(quote! {
/// Returns `true` if the bit is clear (0)
#[inline(always)]
pub fn is_clear(&self) -> bool {
!self.#bits()
}

/// Returns `true` if the bit is set (1)
#[inline(always)]
pub fn is_set(&self) -> bool {
self.#bits()
}
});
}

enum_items.push(
quote! {
/// Value of the field as raw bits
Expand Down Expand Up @@ -957,6 +974,30 @@ pub fn fields(
},
);

let mut pc_r_impl_items = vec![quote! {
/// Value of the field as raw bits
#[inline(always)]
pub fn #bits(&self) -> #fty {
self.bits
}
}];

if f.width == 1 {
pc_r_impl_items.push(quote! {
/// Returns `true` if the bit is clear (0)
#[inline(always)]
pub fn is_clear(&self) -> bool {
!self.#bits()
}

/// Returns `true` if the bit is set (1)
#[inline(always)]
pub fn is_set(&self) -> bool {
self.#bits()
}
});
}

mod_items.push(
quote! {
/// Value of the field
Expand All @@ -965,11 +1006,7 @@ pub fn fields(
}

impl #pc_r {
/// Value of the field as raw bits
#[inline(always)]
pub fn #bits(&self) -> #fty {
self.bits
}
#(#pc_r_impl_items)*
}
},
);
Expand Down