Crate virt [] [src]

A Rust bindings for libvirt.

Libvirt is a portable toolkit to interact with the virtualisation capabilities of Linux, Solaris and other operating systems.

The binding uses standard errors handling from Rust. Each method (there are some exceptions) is returning a type Option or Result.

use virt::connect::Connect;

if let Ok(mut conn) = Connect::open("test://default") {
  conn.close();
}

Most of the structs are automatically release their references by implemementing Drop trait but for structs which are reference counted at C level, it is still possible to explicitly release the reference at Rust level. For instance if a Rust method returns a *Domain, it is possible to call free on it when no longer required.

use virt::connect::Connect;
use virt::domain::Domain;

if let Ok(mut conn) = Connect::open("test://default") {
  if let Ok(mut dom) = Domain::lookup_by_name(&conn, "myguest") {
      dom.free();   // Explicitly releases memory at Rust level.
      conn.close();
  }
}

For each methods accepting or returning a virTypedParameter array a new Rust struct has been defined where each attribute is handling a type Option.

use virt::connect::Connect;
use virt::domain::Domain;

if let Ok(mut conn) = Connect::open("test://default") {
  if let Ok(mut dom) = Domain::lookup_by_name(&conn, "myguest") {
    if let Ok(memp) = dom.get_memory_parameters(0) {
      if memp.hard_limit.is_some() {
        println!("hard limit: {}", memp.hard_limit.unwrap())
      }
    }
  }
  conn.close();
}

Modules

connect
domain
error
interface
network
nodedev
nwfilter
secret
storage_pool
stream
typedparam