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 tries to be a fairly direct mapping of the underling C
API with some differences to respect Rust conventions. So for
example C functions related to a domain like: virDomainCreate
will be mapped in the binding like dom.create() or
virDomainPinVcpu as dom.pin_vcpu.
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") { assert_eq!(Ok(0), 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") { assert_eq!(Ok(()), dom.free()); // Explicitly releases memory at Rust level. assert_eq!(Ok(0), 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(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()) } } } assert_eq!(Ok(0), conn.close()); }
Modules
| connect | |
| domain | |
| error | |
| interface | |
| network | |
| nodedev | |
| nwfilter | |
| secret | |
| storage_pool | |
| storage_vol | |
| stream | |
| typedparam |