disk_backend/
resolve.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Resolver-related definitions for disk resources.
5
6use crate::Disk;
7use crate::DiskIo;
8use crate::InvalidDisk;
9use vm_resource::CanResolveTo;
10use vm_resource::kind::DiskHandleKind;
11
12impl CanResolveTo<ResolvedDisk> for DiskHandleKind {
13    type Input<'a> = ResolveDiskParameters<'a>;
14}
15
16/// Parameters used when resolving a disk resource.
17#[derive(Copy, Clone)]
18pub struct ResolveDiskParameters<'a> {
19    /// Whether the disk is being opened for read-only use.
20    pub read_only: bool,
21    #[doc(hidden)]
22    // Workaround for async_trait not working well with GAT input parameters
23    // with missing lifetimes. Remove once we stop using async_trait for async
24    // resolvers.
25    pub _async_trait_workaround: &'a (),
26}
27
28/// A resolved [`Disk`].
29pub struct ResolvedDisk(pub Disk);
30
31impl ResolvedDisk {
32    /// Returns a resolved disk wrapping a backing object.
33    pub fn new<T: DiskIo>(disk: T) -> Result<Self, InvalidDisk> {
34        Ok(Self(Disk::new(disk)?))
35    }
36}