Skip to content

Suggest: some error should be ok #55

@pbl-pw

Description

@pbl-pw
use arbitrary_int::{u2, u4};
use bitbybit::bitfield;
use custom::Custom1;

mod custom {
    pub struct Custom1<T>(T);
    impl<T: Copy> Custom1<T> {
        pub const fn raw_value(&self) -> T {
            self.0
        }
        pub const fn new_with_raw_value(raw: T) -> Self {
            Self(raw)
        }
    }

    pub struct Custom2<T>(T);
    impl<T: Copy> Custom2<T> {
        pub const fn raw_value(&self) -> T {
            self.0
        }
        pub const fn new_with_raw_value(raw: T) -> Result<Self, T> {
            Ok(Self(raw))
        }
    }
}

#[bitfield(u8)]
#[derive(Debug)]
#[rustfmt::skip]
pub struct Flags {
	#[bits(0..=7, rw)] cus1: Option<custom::Custom2<u8>>, // error, ok if Option<custom::Custom2::<u8>>
	#[bits(2..=5, rw)] cus2: Option<custom::Custom2::<u4>>, // error because require Result<Self, u8> but provide Result<Self, u4>, maybe latter is better especially when used with generic

	#[bits(6..=7, rw)] cus3: custom::Custom1<u2>, // error because '::'
	#[bits(6..=7, rw)] cus4: Custom1<u2>, // error, ok if Custom1::<u2>
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions