hypervisor: adjust new function return type

Make them return wrapped trait object directly.

No functional change.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2022-05-09 21:10:22 +00:00 committed by Liu Wei
parent ad33f7c5e6
commit c3ce5aa5b1
3 changed files with 7 additions and 5 deletions

View File

@ -905,7 +905,8 @@ pub enum KvmError {
pub type KvmResult<T> = result::Result<T, KvmError>;
impl KvmHypervisor {
/// Create a hypervisor based on Kvm
pub fn new() -> hypervisor::Result<KvmHypervisor> {
#[allow(clippy::new_ret_no_self)]
pub fn new() -> hypervisor::Result<Arc<dyn hypervisor::Hypervisor>> {
let kvm_obj = Kvm::new().map_err(|e| hypervisor::HypervisorError::VmCreate(e.into()))?;
let api_version = kvm_obj.get_api_version();
@ -913,7 +914,7 @@ impl KvmHypervisor {
return Err(hypervisor::HypervisorError::IncompatibleApiVersion);
}
Ok(KvmHypervisor { kvm: kvm_obj })
Ok(Arc::new(KvmHypervisor { kvm: kvm_obj }))
}
}
/// Implementation of Hypervisor trait for KVM

View File

@ -74,7 +74,7 @@ pub fn new() -> std::result::Result<Arc<dyn Hypervisor>, HypervisorError> {
#[cfg(feature = "mshv")]
let hv = mshv::MshvHypervisor::new()?;
Ok(Arc::new(hv))
Ok(hv)
}
// Returns a `Vec<T>` with a size in bytes at least as large as `size_in_bytes`.

View File

@ -177,10 +177,11 @@ impl MshvHypervisor {
impl MshvHypervisor {
/// Create a hypervisor based on Mshv
pub fn new() -> hypervisor::Result<MshvHypervisor> {
#[allow(clippy::new_ret_no_self)]
pub fn new() -> hypervisor::Result<Arc<dyn hypervisor::Hypervisor>> {
let mshv_obj =
Mshv::new().map_err(|e| hypervisor::HypervisorError::HypervisorCreate(e.into()))?;
Ok(MshvHypervisor { mshv: mshv_obj })
Ok(Arc::new(MshvHypervisor { mshv: mshv_obj }))
}
}
/// Implementation of Hypervisor trait for Mshv