// Demonstrates ReadOnly* implementing Deref to an inner type.
use read_only::embed;
use std::ops::Deref;

pub struct InnerHandle(pub u64);

#[embed]
pub struct Device {
    #[readonly]
    pub handle: InnerHandle,
    pub counter: i32,
}

impl Device {
    pub fn new(handle: u64) -> Self {
        Self {
            read_only: ReadOnlyDevice {
                handle: InnerHandle(handle),
            },
            counter: 0,
        }
    }
}

// Implement Deref on ReadOnlyDevice for full driver parity
impl Deref for ReadOnlyDevice {
    type Target = InnerHandle;

    fn deref(&self) -> &Self::Target {
        &self.handle
    }
}

fn main() {
    let dev = Device::new(42);
    let _ = dev.handle.0;
    // Chain: Device -> Deref -> ReadOnlyDevice -> Deref -> InnerHandle -> 0
    let _ = dev.0;
}
