pub fn build(&mut self, netif_config: NetworkInterfaceConfig) -> Result<Arc<Mutex<Net>>> {
        let mac_conflict = |net: &Arc<Mutex<Net>>| {
            let net = net.lock().expect("Poisoned lock");
            // Check if another net dev has same MAC.
            netif_config.guest_mac.is_some()
                && netif_config.guest_mac.as_ref() == net.guest_mac()
                && &netif_config.iface_id != net.id()
        };
        // Validate there is no Mac conflict.
        // No need to validate host_dev_name conflict. In such a case,
        // an error will be thrown during device creation anyway.
        if self.net_devices.iter().any(mac_conflict) {
            return Err(NetworkInterfaceError::GuestMacAddressInUse(
                netif_config.guest_mac.unwrap().to_string(),
            ));
        }

        // If this is an update, just remove the old one.
        if let Some(index) = self
            .net_devices
            .iter()
            .position(|net| net.lock().expect("Poisoned lock").id() == &netif_config.iface_id)
        {
            self.net_devices.swap_remove(index);
        }

        // Add new device.
        let net = Arc::new(Mutex::new(Self::create_net(netif_config)?));
        self.net_devices.push(net.clone());

        Ok(net)
    }
/// Builds a network device based on a network interface config. Keeps a device reference
/// in the builder's internal list.
Builds a network device based on a network interface config. Keeps a device reference
in the builder's internal list.
Builds a network device based on a network interface config . Keeps a device reference in the builder ' s internal list .
pub fn build(&mut self, netif_config: NetworkInterfaceConfig) -> Result<Arc<Mutex<Net>>> {
        let mac_conflict = |net: &Arc<Mutex<Net>>| {
            let net = net.lock().expect("Poisoned lock");
            // Check if another net dev has same MAC.
            netif_config.guest_mac.is_some()
                && netif_config.guest_mac.as_ref() == net.guest_mac()
                && &netif_config.iface_id != net.id()
        };
        // Validate there is no Mac conflict.
        // No need to validate host_dev_name conflict. In such a case,
        // an error will be thrown during device creation anyway.
        if self.net_devices.iter().any(mac_conflict) {
            return Err(NetworkInterfaceError::GuestMacAddressInUse(
                netif_config.guest_mac.unwrap().to_string(),
            ));
        }
        // If this is an update, just remove the old one.
        if let Some(index) = self
            .net_devices
            .iter()
            .position(|net| net.lock().expect("Poisoned lock").id() == &netif_config.iface_id)
        {
            self.net_devices.swap_remove(index);
        }
        // Add new device.
        let net = Arc::new(Mutex::new(Self::create_net(netif_config)?));
        self.net_devices.push(net.clone());
        Ok(net)
    }
pub fn build ( & mut self , netif_config : NetworkInterfaceConfig ) -> Result < Arc < Mutex < Net > > > { let mac_conflict = | net : & Arc < Mutex < Net > > | { let net = net . lock ( ) . expect ( " " ) ; // Check if another net dev has same MAC. netif_config . guest_mac . is_some ( ) && netif_config . guest_mac . as_ref ( ) == net . guest_mac ( ) && & netif_config . iface_id != net . id ( ) } ; // Validate there is no Mac conflict. // No need to validate host_dev_name conflict. In such a case, // an error will be thrown during device creation anyway. if self . net_devices . iter ( ) . any ( mac_conflict ) { return Err ( NetworkInterfaceError :: GuestMacAddressInUse ( netif_config . guest_mac . unwrap ( ) . to_string ( ) , ) ) ; } // If this is an update, just remove the old one. if let Some ( index ) = self . net_devices . iter ( ) . position ( | net | net . lock ( ) . expect ( " " ) . id ( ) == & netif_config . iface_id ) { self . net_devices . swap_remove ( index ) ; } // Add new device. let net = Arc :: new ( Mutex :: new ( Self :: create_net ( netif_config ) ? ) ) ; self . net_devices . push ( net . clone ( ) ) ; Ok ( net ) }
Builds a network device based on a network interface config.
Builds a network device based on a network interface config .
&mut self
netif_config
NetworkInterfaceConfig
&mut self
netif_config
NetworkInterfaceConfig