summaryrefslogtreecommitdiff
path: root/src/image.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-03-07 17:07:20 +0200
committerLars Wirzenius <liw@liw.fi>2021-03-07 17:07:20 +0200
commit1e8ba95def26de67f8fd618549d6b8f80a14ddd8 (patch)
treedc4916152d7c1f488174a7297863e89bad8daa03 /src/image.rs
parent54f0cba69a023ccf0b781dd76a2b370bf6400585 (diff)
downloadvmadm-1e8ba95def26de67f8fd618549d6b8f80a14ddd8.tar.gz
doc: add doc comments to crate
Diffstat (limited to 'src/image.rs')
-rw-r--r--src/image.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/image.rs b/src/image.rs
index db6102f..62f80f7 100644
--- a/src/image.rs
+++ b/src/image.rs
@@ -1,26 +1,34 @@
+//! Virtual machine image handling.
+
use std::fs::copy;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::result::Result;
+/// Errors from this module.
#[derive(Debug, thiserror::Error)]
pub enum ImageError {
+ /// Error resizing image.
#[error("qemu-img resize failed: {0}")]
ResizeError(String),
+ /// I/O error.
#[error(transparent)]
IoError(#[from] std::io::Error),
+ /// Error parsing a string as UTF8.
#[error(transparent)]
StringError(#[from] std::string::FromUtf8Error),
}
+/// A virtual machine image.
#[derive(Debug, Clone)]
pub struct VirtualMachineImage {
filename: PathBuf,
}
impl VirtualMachineImage {
+ /// Create new image from a base image.
pub fn new_from_base(base_image: &Path, image: &Path) -> Result<Self, ImageError> {
copy(base_image, image)?;
Ok(Self {
@@ -28,10 +36,12 @@ impl VirtualMachineImage {
})
}
+ /// Filename of the image.
pub fn filename(&self) -> &Path {
&self.filename
}
+ /// Change size of image.
pub fn resize(&self, new_size: u64) -> Result<(), ImageError> {
let r = Command::new("qemu-img")
.arg("resize")