pub fn create_device_topology(device_infos: Vec<fdd::DeviceInfo>) -> Vec<DeviceNode> {
    let device_infos: Vec<Rc<fdd::DeviceInfo>> =
        device_infos.into_iter().map(|device_info| Rc::new(device_info)).collect();
    // Key: ID of the vertex
    let device_vertices: HashMap<u64, DeviceVertex> = device_infos
        .iter()
        .map(|device_info| {
            (device_info.id.expect("Device ID missing"), Rc::clone(&device_info).into())
        })
        .collect();
    assert!(!is_cyclic(&device_vertices), "Device topology is cyclic");

    // Assert that the devices' children and parents make sense.
    let mut root_ids: Vec<u64> = Vec::new();
    for device_info in device_infos {
        let id = device_info.id.expect("Device ID missing");

        // Assert all device's children exist.
        if let Some(child_ids) = device_info.child_ids.as_ref() {
            for child_id in child_ids {
                // Child device may or may not exist depending on the filter
                // sent in GetDeviceInfo.
                if let Some(child_node) = device_vertices.get(child_id) {
                    assert!(child_node.parent_ids.contains(&id), "Parent device lists the ID of a child device in it's child ID's, however, the child device does not list the parent device's ID in its parent devices");
                }
            }
        }

        // Find root and assert non-root devices' parents exist.
        if let Some(parent_ids) = device_info.parent_ids.as_ref() {
            for parent_id in parent_ids {
                // Parent device may or may not exist depending on the filter
                // sent in GetDeviceInfo or if the current device is a root
                // device.
                if let Some(parent_node) = device_vertices.get(parent_id) {
                    assert!(parent_node.child_ids.contains(&id), "Child device lists the ID of a parent device in it's parent ID's, however, the parent device does not list the child device's ID in its child devices");
                } else {
                    root_ids.push(id);
                }
            }
        } else {
            root_ids.push(id);
        }
    }

    root_ids
        .into_iter()
        .map(|root_id| device_vertex_to_device_node(root_id, &device_vertices))
        .collect::<Vec<DeviceNode>>()
}
/// Creates zero or more tree structures that reflects the DFv1 devices' or DFv2
/// nodes' topology defined in `device_infos`. Note that if two devices/nodes
/// share a child then that child will be duplicated so that each parent has a
/// copy of the child.
///
/// # Panics
///
/// Panics if one of the resulting graphs is cyclic or if `device_infos`
/// contains conflicting information about the devices'/nodes' topology or if a
/// device's/node's ID or topological path is missing.
Creates zero or more tree structures that reflects the DFv1 devices' or DFv2
nodes' topology defined in `device_infos`. Note that if two devices/nodes
share a child then that child will be duplicated so that each parent has a
copy of the child.
Creates zero or more tree structures that reflects the DFv1 devices ' or DFv2 nodes ' topology defined in ` device_infos ` . Note that if two devices / nodes share a child then that child will be duplicated so that each parent has a copy of the child .
pub fn create_device_topology(device_infos: Vec<fdd::DeviceInfo>) -> Vec<DeviceNode> {
    let device_infos: Vec<Rc<fdd::DeviceInfo>> =
        device_infos.into_iter().map(|device_info| Rc::new(device_info)).collect();
    // Key: ID of the vertex
    let device_vertices: HashMap<u64, DeviceVertex> = device_infos
        .iter()
        .map(|device_info| {
            (device_info.id.expect("Device ID missing"), Rc::clone(&device_info).into())
        })
        .collect();
    assert!(!is_cyclic(&device_vertices), "Device topology is cyclic");
    // Assert that the devices' children and parents make sense.
    let mut root_ids: Vec<u64> = Vec::new();
    for device_info in device_infos {
        let id = device_info.id.expect("Device ID missing");
        // Assert all device's children exist.
        if let Some(child_ids) = device_info.child_ids.as_ref() {
            for child_id in child_ids {
                // Child device may or may not exist depending on the filter
                // sent in GetDeviceInfo.
                if let Some(child_node) = device_vertices.get(child_id) {
                    assert!(child_node.parent_ids.contains(&id), "Parent device lists the ID of a child device in it's child ID's, however, the child device does not list the parent device's ID in its parent devices");
                }
            }
        }
        // Find root and assert non-root devices' parents exist.
        if let Some(parent_ids) = device_info.parent_ids.as_ref() {
            for parent_id in parent_ids {
                // Parent device may or may not exist depending on the filter
                // sent in GetDeviceInfo or if the current device is a root
                // device.
                if let Some(parent_node) = device_vertices.get(parent_id) {
                    assert!(parent_node.child_ids.contains(&id), "Child device lists the ID of a parent device in it's parent ID's, however, the parent device does not list the child device's ID in its child devices");
                } else {
                    root_ids.push(id);
                }
            }
        } else {
            root_ids.push(id);
        }
    }
    root_ids
        .into_iter()
        .map(|root_id| device_vertex_to_device_node(root_id, &device_vertices))
        .collect::<Vec<DeviceNode>>()
}
pub fn create_device_topology ( device_infos : Vec < fdd :: DeviceInfo > ) -> Vec < DeviceNode > { let device_infos : Vec < Rc < fdd :: DeviceInfo > > = device_infos . into_iter ( ) . map ( | device_info | Rc :: new ( device_info ) ) . collect ( ) ; // Key: ID of the vertex let device_vertices : HashMap < u64 , DeviceVertex > = device_infos . iter ( ) . map ( | device_info | { ( device_info . id . expect ( " " ) , Rc :: clone ( & device_info ) . into ( ) ) } ) . collect ( ) ; assert ! ( is_cyclic ( device_vertices ) " " ) ; // Assert that the devices' children and parents make sense. let mut root_ids : Vec < u64 > = Vec :: new ( ) ; for device_info in device_infos { let id = device_info . id . expect ( " " ) ; // Assert all device's children exist. if let Some ( child_ids ) = device_info . child_ids . as_ref ( ) { for child_id in child_ids { // Child device may or may not exist depending on the filter // sent in GetDeviceInfo. if let Some ( child_node ) = device_vertices . get ( child_id ) { assert ! ( child_node parent_ids contains ( id ) " " ) ; } } } // Find root and assert non-root devices' parents exist. if let Some ( parent_ids ) = device_info . parent_ids . as_ref ( ) { for parent_id in parent_ids { // Parent device may or may not exist depending on the filter // sent in GetDeviceInfo or if the current device is a root // device. if let Some ( parent_node ) = device_vertices . get ( parent_id ) { assert ! ( parent_node child_ids contains ( id ) " " ) ; } else { root_ids . push ( id ) ; } } } else { root_ids . push ( id ) ; } } root_ids . into_iter ( ) . map ( | root_id | device_vertex_to_device_node ( root_id , & device_vertices ) ) . collect :: < Vec < DeviceNode > > ( ) }
Creates zero or more tree structures that reflects the DFv1 devices' or DFv2
nodes' topology defined in `device_infos`.
Creates zero or more tree structures that reflects the DFv1 devices ' or DFv2 nodes ' topology defined in ` device_infos ` .
device_infos
Vec<fdd::DeviceInfo>
device_infos
Vec<fdd::DeviceInfo>
panics
Panics if one of the resulting graphs is cyclic or if `device_infos`
contains conflicting information about the devices'/nodes' topology or if a
device's/node's ID or topological path is missing.
Panics if one of the resulting graphs is cyclic or if ` device_infos ` contains conflicting information about the devices ' / nodes ' topology or if a device ' s / node ' s ID or topological path is missing .