twizzler_driver/device/
info.rsuse twizzler_abi::device::SubObjectType;
use twizzler_object::{ObjID, Object, ObjectInitError, ObjectInitFlags, Protections};
use super::Device;
pub struct InfoObject<T> {
obj: Object<T>,
}
impl<T> InfoObject<T> {
fn new(id: ObjID) -> Result<Self, ObjectInitError> {
Ok(Self {
obj: Object::init_id(id, Protections::READ, ObjectInitFlags::empty())?,
})
}
pub fn get_data(&self) -> &T {
unsafe { self.obj.base_unchecked() }
}
}
impl Device {
pub unsafe fn get_info<T>(&self, idx: u8) -> Option<InfoObject<T>> {
let id = self.get_subobj(SubObjectType::Info.into(), idx)?;
InfoObject::new(id).ok()
}
}