vim_rs 0.4.4

Rust Bindings for the VMware by Broadcom vCenter VI JSON API
Documentation
use super::super::types::vim_any::VimAny;
use crate::types::structs::{
    ManagedObjectReference, ObjectSpec, PropertySpec, SelectionSpec, TraversalSpec,
};

/// Trait for errors that can be properly boxed and sent across threads
pub trait BoxableError: std::error::Error + Send + Sync + 'static {}

// Blanket implementation for all types that satisfy the requirements
impl<E: std::error::Error + Send + Sync + 'static> BoxableError for E {}

// Re-export the unified error types for backwards compatibility within this module
pub use super::error::{Error, Result};

/// Get the type name from a VimAny value. This is used for error reporting.
pub fn type_name(value: &VimAny) -> String {
    match value {
        VimAny::Value(value) => {
            let type_name = value.as_str();
            type_name.to_string()
        }
        VimAny::Object(obj) => {
            let type_name = obj.data_type().as_str();
            type_name.to_string()
        }
    }
}

/// A trait for objects that can be queried using the PropertyCollector utilities. These objects
/// provide a `PropertySpec` for the object type.
pub trait Queriable {
    /// The property spec for this object type.
    fn prop_spec() -> PropertySpec;
}

/// Create an ObjectSpec for a view. This is used to specify objects to be monitored from a view.
pub(crate) fn obj_spec_for_view(view_moref: ManagedObjectReference) -> Vec<ObjectSpec> {
    let r#type = view_moref.r#type.clone();
    vec![ObjectSpec {
        obj: view_moref,
        skip: Some(false),
        select_set: Some(vec![Box::new(TraversalSpec {
            selection_spec_: SelectionSpec {
                name: Some("traverseEntities".to_string()),
            },
            r#type: r#type.as_str().to_string(),
            path: "view".to_string(),
            skip: Some(false),
            select_set: None,
        })]),
    }]
}