Skip to content

Commit

Permalink
moved build method to the generic ConstrainedFlag type
Browse files Browse the repository at this point in the history
  • Loading branch information
GTimothy committed Nov 4, 2024
1 parent 8574ffc commit 53bd532
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions rust/kernel/bitflag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct Valid<Part> {
#[allow(unused_variables)]
#[allow(dead_code)]
fn simple_size_colour_bitflag() {
use crate::macros::bitflag;
use crate::bitflag::{bitflag, ConstrainedFlag};

const BIG: u32 = 0u32;
const SMALL: u32 = 1u32;
Expand All @@ -67,7 +67,7 @@ fn simple_size_colour_bitflag() {
},
];

let flag_builder = CustomBitFlag::builder();
let flag_builder = ConstrainedFlag::<CustomBitFlag>::builder();
let flag = flag_builder.with_big().with_red().build();
assert_eq!(flag.0, BIG | RED);
}
8 changes: 4 additions & 4 deletions rust/macros/bitflag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ pub(crate) fn bitflag_and_builder(ts: TokenStream) -> TokenStream {
type Bits = {type};
}}
impl {name} {{
impl crate::bitflag::ConstrainedFlag::<{name}> {{
pub fn builder() -> {name}Builder<{missing_generics}> {{
{name}Builder {{
flags: Default::default(),
Expand All @@ -285,9 +285,9 @@ pub(crate) fn bitflag_and_builder(ts: TokenStream) -> TokenStream {
{missing_impls}
impl ConstrainedFlagBuilder<{name}> for {name}Builder<{valid_generics}> {{
fn build(self) -> ConstrainedFlag<{name}> {{
ConstrainedFlag::<{name}>(self.flags.iter().flatten().sum::<{type}>())
impl crate::bitflag::ConstrainedFlagBuilder<{name}> for {name}Builder<{valid_generics}> {{
fn build(self) -> crate::bitflag::ConstrainedFlag<{name}> {{
crate::bitflag::ConstrainedFlag::<{name}>(self.flags.iter().flatten().sum::<{type}>())
}}
}}
",
Expand Down

0 comments on commit 53bd532

Please sign in to comment.