virtualbox_rs 0.4.2

A Rust library for interacting with VirtualBox, providing a safe and idiomatic interface to the VirtualBox API.
Documentation
use crate::event_detail::DetailEvent;
#[cfg(not(is_v_7_1_or_newer))]
use crate::event_detail::utility::cast_event;
#[cfg(not(is_v_7_1_or_newer))]
use crate::utility::macros::macros::get_function_result_bool;
#[cfg(not(is_v_7_1_or_newer))]
use crate::VboxError;
#[cfg(not(is_v_7_1_or_newer))]
use log::error;
use std::fmt::Display;
#[cfg(not(is_v_7_1_or_newer))]
use vbox_raw::sys_lib::{IRecordingChangedEvent, IRECORDINGCHANGEDEVENT_IID_STR};
use vbox_raw::sys_lib::IEvent;

/// Notification when recording settings have changed
#[derive(Debug)]
pub struct RecordingChangedEvent {
    pub midl_does_not_like_empty_interfaces: bool,
}

#[cfg(not(is_v_7_1_or_newer))]
impl RecordingChangedEvent {
    pub fn new(object: *mut IEvent) -> DetailEvent {
        match Self::create(object) {
            Ok(detail) => DetailEvent::RecordingChangedEvent(detail),
            Err(err) => {
                error!("RecordingChangedEvent error:{}", err);
                DetailEvent::Null
            }
        }
    }
    fn create(object: *mut IEvent) -> Result<Self, VboxError> {
        let obj1 = cast_event(object, IRECORDINGCHANGEDEVENT_IID_STR)?;
        let midl_does_not_like_empty_interfaces =
            Self::get_midl_does_not_like_empty_interfaces(obj1)?;
        Ok(Self {
            midl_does_not_like_empty_interfaces,
        })
    }

    fn get_midl_does_not_like_empty_interfaces(
        new_obj: *mut IRecordingChangedEvent,
    ) -> Result<bool, VboxError> {
        get_function_result_bool!(new_obj, GetMidlDoesNotLikeEmptyInterfaces)
    }
}

#[cfg(is_v_7_1_or_newer)]
impl RecordingChangedEvent {
    pub fn new(_object: *mut IEvent) -> DetailEvent {
        DetailEvent::Null
    }
}
impl Display for RecordingChangedEvent {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let s = format!("{:?}", self);
        write!(f, "{}", format!("{}", s))
    }
}