imago/qcow2/
sync_wrappers.rs

1//! Synchronous wrapper around qcow2 functions.
2
3use super::*;
4
5impl<S: Storage + 'static, F: WrappedFormat<S> + 'static> Qcow2<S, F> {
6    /// Synchronous wrapper around [`Qcow2::open_image()`].
7    ///
8    /// Runs the async function in an ephemeral tokio runtime.
9    pub fn open_image_sync(metadata: S, writable: bool) -> io::Result<Self> {
10        tokio::runtime::Builder::new_current_thread()
11            .build()?
12            .block_on(Self::open_image(metadata, writable))
13    }
14
15    /// Synchronous wrapper around [`Qcow2::open_path()`].
16    ///
17    /// Runs the async function in an ephemeral tokio runtime.
18    pub fn open_path_sync<P: AsRef<Path>>(path: P, writable: bool) -> io::Result<Self> {
19        tokio::runtime::Builder::new_current_thread()
20            .build()?
21            .block_on(Self::open_path(path, writable))
22    }
23
24    /// Synchronous wrapper around [`Qcow2::open_implicit_dependencies()`].
25    ///
26    /// Runs the async function in an ephemeral tokio runtime.
27    pub fn open_implicit_dependencies_sync(&mut self) -> io::Result<()> {
28        tokio::runtime::Builder::new_current_thread()
29            .build()?
30            .block_on(self.open_implicit_dependencies())
31    }
32}