disk_layered/
resolve.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

//! Resolver-related definitions for disk layer resources.

use super::DiskLayer;
use crate::LayerAttach;
use vm_resource::CanResolveTo;
use vm_resource::kind::DiskLayerHandleKind;

impl CanResolveTo<ResolvedDiskLayer> for DiskLayerHandleKind {
    type Input<'a> = ResolveDiskLayerParameters<'a>;
}

/// Parameters used when resolving a disk layer resource.
#[derive(Copy, Clone)]
pub struct ResolveDiskLayerParameters<'a> {
    /// Whether the layer is being opened for read-only use.
    pub read_only: bool,
    #[doc(hidden)]
    // Workaround for async_trait not working well with GAT input parameters
    // with missing lifetimes. Remove once we stop using async_trait for async
    // resolvers.
    pub _async_trait_workaround: &'a (),
}

/// A resolved [`DiskLayer`].
pub struct ResolvedDiskLayer(pub DiskLayer);

impl ResolvedDiskLayer {
    /// Returns a resolved disk wrapping a backing object.
    pub fn new<T: LayerAttach>(layer: T) -> Self {
        Self(DiskLayer::new(layer))
    }
}