mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-05 21:15:45 +00:00
hypervisor: use proper doc tests for examples
It seems like these examples were always intended to be doctests, since there are lines marked with "#" so that they are excluded from the generated documentation, but they were not recognised as doc tests because they were not formatted correctly. The code needed some adjustments so that it would actually compile and run as doctests. Signed-off-by: Alyssa Ross <hi@alyssa.is>
This commit is contained in:
parent
1ed4898d28
commit
755cabea4c
@ -335,16 +335,17 @@ impl KvmVm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
|
||||||
/// Implementation of Vm trait for KVM
|
/// Implementation of Vm trait for KVM
|
||||||
/// Example:
|
|
||||||
/// #[cfg(feature = "kvm")]
|
|
||||||
/// extern crate hypervisor
|
|
||||||
/// let kvm = hypervisor::kvm::KvmHypervisor::new().unwrap();
|
|
||||||
/// let hypervisor: Arc<dyn hypervisor::Hypervisor> = Arc::new(kvm);
|
|
||||||
/// let vm = hypervisor.create_vm().expect("new VM fd creation failed");
|
|
||||||
/// vm.set/get().unwrap()
|
|
||||||
///
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use hypervisor::kvm::KvmHypervisor;
|
||||||
|
/// # use std::sync::Arc;
|
||||||
|
/// let kvm = KvmHypervisor::new().unwrap();
|
||||||
|
/// let hypervisor = Arc::new(kvm);
|
||||||
|
/// let vm = hypervisor.create_vm().expect("new VM fd creation failed");
|
||||||
|
/// ```
|
||||||
impl vm::Vm for KvmVm {
|
impl vm::Vm for KvmVm {
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
///
|
///
|
||||||
@ -917,13 +918,16 @@ impl KvmHypervisor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Implementation of Hypervisor trait for KVM
|
/// Implementation of Hypervisor trait for KVM
|
||||||
/// Example:
|
|
||||||
/// #[cfg(feature = "kvm")]
|
|
||||||
/// extern crate hypervisor
|
|
||||||
/// let kvm = hypervisor::kvm::KvmHypervisor::new().unwrap();
|
|
||||||
/// let hypervisor: Arc<dyn hypervisor::Hypervisor> = Arc::new(kvm);
|
|
||||||
/// let vm = hypervisor.create_vm().expect("new VM fd creation failed");
|
|
||||||
///
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use hypervisor::kvm::KvmHypervisor;
|
||||||
|
/// # use std::sync::Arc;
|
||||||
|
/// let kvm = KvmHypervisor::new().unwrap();
|
||||||
|
/// let hypervisor = Arc::new(kvm);
|
||||||
|
/// let vm = hypervisor.create_vm().expect("new VM fd creation failed");
|
||||||
|
/// ```
|
||||||
impl hypervisor::Hypervisor for KvmHypervisor {
|
impl hypervisor::Hypervisor for KvmHypervisor {
|
||||||
///
|
///
|
||||||
/// Returns the type of the hypervisor
|
/// Returns the type of the hypervisor
|
||||||
@ -932,13 +936,15 @@ impl hypervisor::Hypervisor for KvmHypervisor {
|
|||||||
HypervisorType::Kvm
|
HypervisorType::Kvm
|
||||||
}
|
}
|
||||||
/// Create a KVM vm object of a specific VM type and return the object as Vm trait object
|
/// Create a KVM vm object of a specific VM type and return the object as Vm trait object
|
||||||
/// Example
|
|
||||||
/// # extern crate hypervisor;
|
|
||||||
/// # use hypervisor::KvmHypervisor;
|
|
||||||
/// use hypervisor::KvmVm;
|
|
||||||
/// let hypervisor = KvmHypervisor::new().unwrap();
|
|
||||||
/// let vm = hypervisor.create_vm_with_type(KvmVmType::LegacyVm).unwrap()
|
|
||||||
///
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use hypervisor::kvm::KvmHypervisor;
|
||||||
|
/// use hypervisor::kvm::KvmVm;
|
||||||
|
/// let hypervisor = KvmHypervisor::new().unwrap();
|
||||||
|
/// let vm = hypervisor.create_vm_with_type(0).unwrap();
|
||||||
|
/// ```
|
||||||
fn create_vm_with_type(&self, vm_type: u64) -> hypervisor::Result<Arc<dyn vm::Vm>> {
|
fn create_vm_with_type(&self, vm_type: u64) -> hypervisor::Result<Arc<dyn vm::Vm>> {
|
||||||
let fd: VmFd;
|
let fd: VmFd;
|
||||||
loop {
|
loop {
|
||||||
@ -992,13 +998,15 @@ impl hypervisor::Hypervisor for KvmHypervisor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create a KVM vm object and return the object as Vm trait object
|
/// Create a KVM vm object and return the object as Vm trait object
|
||||||
/// Example
|
|
||||||
/// # extern crate hypervisor;
|
|
||||||
/// # use hypervisor::KvmHypervisor;
|
|
||||||
/// use hypervisor::KvmVm;
|
|
||||||
/// let hypervisor = KvmHypervisor::new().unwrap();
|
|
||||||
/// let vm = hypervisor.create_vm().unwrap()
|
|
||||||
///
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use hypervisor::kvm::KvmHypervisor;
|
||||||
|
/// use hypervisor::kvm::KvmVm;
|
||||||
|
/// let hypervisor = KvmHypervisor::new().unwrap();
|
||||||
|
/// let vm = hypervisor.create_vm().unwrap();
|
||||||
|
/// ```
|
||||||
fn create_vm(&self) -> hypervisor::Result<Arc<dyn vm::Vm>> {
|
fn create_vm(&self) -> hypervisor::Result<Arc<dyn vm::Vm>> {
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
let mut vm_type: u64 = 0; // Create with default platform type
|
let mut vm_type: u64 = 0; // Create with default platform type
|
||||||
@ -1087,15 +1095,17 @@ pub struct KvmVcpu {
|
|||||||
hyperv_synic: AtomicBool,
|
hyperv_synic: AtomicBool,
|
||||||
}
|
}
|
||||||
/// Implementation of Vcpu trait for KVM
|
/// Implementation of Vcpu trait for KVM
|
||||||
/// Example:
|
///
|
||||||
/// #[cfg(feature = "kvm")]
|
/// # Examples
|
||||||
/// extern crate hypervisor
|
///
|
||||||
/// let kvm = hypervisor::kvm::KvmHypervisor::new().unwrap();
|
/// ```
|
||||||
/// let hypervisor: Arc<dyn hypervisor::Hypervisor> = Arc::new(kvm);
|
/// # use hypervisor::kvm::KvmHypervisor;
|
||||||
|
/// # use std::sync::Arc;
|
||||||
|
/// let kvm = KvmHypervisor::new().unwrap();
|
||||||
|
/// let hypervisor = Arc::new(kvm);
|
||||||
/// let vm = hypervisor.create_vm().expect("new VM fd creation failed");
|
/// let vm = hypervisor.create_vm().expect("new VM fd creation failed");
|
||||||
/// let vcpu = vm.create_vcpu(0, None).unwrap();
|
/// let vcpu = vm.create_vcpu(0, None).unwrap();
|
||||||
/// vcpu.get/set().unwrap()
|
/// ```
|
||||||
///
|
|
||||||
impl cpu::Vcpu for KvmVcpu {
|
impl cpu::Vcpu for KvmVcpu {
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
///
|
///
|
||||||
@ -1797,11 +1807,10 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # extern crate hypervisor;
|
/// # use hypervisor::kvm::KvmHypervisor;
|
||||||
/// # use hypervisor::KvmHypervisor;
|
|
||||||
/// # use std::sync::Arc;
|
/// # use std::sync::Arc;
|
||||||
/// let kvm = hypervisor::kvm::KvmHypervisor::new().unwrap();
|
/// let kvm = KvmHypervisor::new().unwrap();
|
||||||
/// let hv: Arc<dyn hypervisor::Hypervisor> = Arc::new(kvm);
|
/// let hv = Arc::new(kvm);
|
||||||
/// let vm = hv.create_vm().expect("new VM fd creation failed");
|
/// let vm = hv.create_vm().expect("new VM fd creation failed");
|
||||||
/// vm.enable_split_irq().unwrap();
|
/// vm.enable_split_irq().unwrap();
|
||||||
/// let vcpu = vm.create_vcpu(0, None).unwrap();
|
/// let vcpu = vm.create_vcpu(0, None).unwrap();
|
||||||
@ -1969,11 +1978,10 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # extern crate hypervisor;
|
/// # use hypervisor::kvm::KvmHypervisor;
|
||||||
/// # use hypervisor::KvmHypervisor;
|
|
||||||
/// # use std::sync::Arc;
|
/// # use std::sync::Arc;
|
||||||
/// let kvm = hypervisor::kvm::KvmHypervisor::new().unwrap();
|
/// let kvm = KvmHypervisor::new().unwrap();
|
||||||
/// let hv: Arc<dyn hypervisor::Hypervisor> = Arc::new(kvm);
|
/// let hv = Arc::new(kvm);
|
||||||
/// let vm = hv.create_vm().expect("new VM fd creation failed");
|
/// let vm = hv.create_vm().expect("new VM fd creation failed");
|
||||||
/// vm.enable_split_irq().unwrap();
|
/// vm.enable_split_irq().unwrap();
|
||||||
/// let vcpu = vm.create_vcpu(0, None).unwrap();
|
/// let vcpu = vm.create_vcpu(0, None).unwrap();
|
||||||
|
@ -195,13 +195,16 @@ impl MshvHypervisor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Implementation of Hypervisor trait for Mshv
|
/// Implementation of Hypervisor trait for Mshv
|
||||||
/// Example:
|
|
||||||
/// #[cfg(feature = "mshv")]
|
|
||||||
/// extern crate hypervisor
|
|
||||||
/// let mshv = hypervisor::mshv::MshvHypervisor::new().unwrap();
|
|
||||||
/// let hypervisor: Arc<dyn hypervisor::Hypervisor> = Arc::new(mshv);
|
|
||||||
/// let vm = hypervisor.create_vm().expect("new VM fd creation failed");
|
|
||||||
///
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use hypervisor::mshv::MshvHypervisor;
|
||||||
|
/// # use std::sync::Arc;
|
||||||
|
/// let mshv = MshvHypervisor::new().unwrap();
|
||||||
|
/// let hypervisor = Arc::new(mshv);
|
||||||
|
/// let vm = hypervisor.create_vm().expect("new VM fd creation failed");
|
||||||
|
/// ```
|
||||||
impl hypervisor::Hypervisor for MshvHypervisor {
|
impl hypervisor::Hypervisor for MshvHypervisor {
|
||||||
///
|
///
|
||||||
/// Returns the type of the hypervisor
|
/// Returns the type of the hypervisor
|
||||||
@ -210,13 +213,16 @@ impl hypervisor::Hypervisor for MshvHypervisor {
|
|||||||
HypervisorType::Mshv
|
HypervisorType::Mshv
|
||||||
}
|
}
|
||||||
/// Create a mshv vm object and return the object as Vm trait object
|
/// Create a mshv vm object and return the object as Vm trait object
|
||||||
/// Example
|
|
||||||
/// # extern crate hypervisor;
|
|
||||||
/// # use hypervisor::MshvHypervisor;
|
|
||||||
/// use hypervisor::MshvVm;
|
|
||||||
/// let hypervisor = MshvHypervisor::new().unwrap();
|
|
||||||
/// let vm = hypervisor.create_vm().unwrap()
|
|
||||||
///
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # extern crate hypervisor;
|
||||||
|
/// # use hypervisor::mshv::MshvHypervisor;
|
||||||
|
/// use hypervisor::mshv::MshvVm;
|
||||||
|
/// let hypervisor = MshvHypervisor::new().unwrap();
|
||||||
|
/// let vm = hypervisor.create_vm().unwrap();
|
||||||
|
/// ```
|
||||||
fn create_vm(&self) -> hypervisor::Result<Arc<dyn vm::Vm>> {
|
fn create_vm(&self) -> hypervisor::Result<Arc<dyn vm::Vm>> {
|
||||||
let fd: VmFd;
|
let fd: VmFd;
|
||||||
loop {
|
loop {
|
||||||
@ -285,15 +291,17 @@ pub struct MshvVcpu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Implementation of Vcpu trait for Microsoft Hypervisor
|
/// Implementation of Vcpu trait for Microsoft Hypervisor
|
||||||
/// Example:
|
|
||||||
/// #[cfg(feature = "mshv")]
|
|
||||||
/// extern crate hypervisor
|
|
||||||
/// let mshv = hypervisor::mshv::MshvHypervisor::new().unwrap();
|
|
||||||
/// let hypervisor: Arc<dyn hypervisor::Hypervisor> = Arc::new(mshv);
|
|
||||||
/// let vm = hypervisor.create_vm().expect("new VM fd creation failed");
|
|
||||||
/// let vcpu = vm.create_vcpu(0).unwrap();
|
|
||||||
/// vcpu.get/set().unwrap()
|
|
||||||
///
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use hypervisor::mshv::MshvHypervisor;
|
||||||
|
/// # use std::sync::Arc;
|
||||||
|
/// let mshv = MshvHypervisor::new().unwrap();
|
||||||
|
/// let hypervisor = Arc::new(mshv);
|
||||||
|
/// let vm = hypervisor.create_vm().expect("new VM fd creation failed");
|
||||||
|
/// let vcpu = vm.create_vcpu(0, None).unwrap();
|
||||||
|
/// ```
|
||||||
impl cpu::Vcpu for MshvVcpu {
|
impl cpu::Vcpu for MshvVcpu {
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
///
|
///
|
||||||
@ -917,15 +925,17 @@ impl MshvVm {
|
|||||||
|
|
||||||
///
|
///
|
||||||
/// Implementation of Vm trait for Mshv
|
/// Implementation of Vm trait for Mshv
|
||||||
/// Example:
|
|
||||||
/// #[cfg(feature = "mshv")]
|
|
||||||
/// # extern crate hypervisor;
|
|
||||||
/// # use hypervisor::MshvHypervisor;
|
|
||||||
/// let mshv = MshvHypervisor::new().unwrap();
|
|
||||||
/// let hypervisor: Arc<dyn hypervisor::Hypervisor> = Arc::new(mshv);
|
|
||||||
/// let vm = hypervisor.create_vm().expect("new VM fd creation failed");
|
|
||||||
/// vm.set/get().unwrap()
|
|
||||||
///
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # extern crate hypervisor;
|
||||||
|
/// # use hypervisor::mshv::MshvHypervisor;
|
||||||
|
/// # use std::sync::Arc;
|
||||||
|
/// let mshv = MshvHypervisor::new().unwrap();
|
||||||
|
/// let hypervisor = Arc::new(mshv);
|
||||||
|
/// let vm = hypervisor.create_vm().expect("new VM fd creation failed");
|
||||||
|
/// ```
|
||||||
impl vm::Vm for MshvVm {
|
impl vm::Vm for MshvVm {
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user