1use crate::{Qcow1, Qcow2, Snapshot};
2
3#[derive(Debug)]
5pub enum DynamicQcow {
6 Qcow1(Qcow1),
8
9 Qcow2(Qcow2),
11}
12
13impl DynamicQcow {
14 pub fn snapshots(&self) -> &[Snapshot] {
16 #[allow(unreachable_patterns)]
17 match self {
18 Self::Qcow2(qcow) => &qcow.snapshots,
19 _ => &[],
20 }
21 }
22
23 pub fn version(&self) -> u32 {
25 match self {
26 Self::Qcow2(qcow) => qcow.header.version,
27 Self::Qcow1(_) => 1,
28 }
29 }
30
31 pub fn cluster_size(&self) -> u64 {
33 match self {
34 Self::Qcow2(qcow) => qcow.cluster_size(),
35 Self::Qcow1(qcow) => qcow.cluster_size(),
36 }
37 }
38
39 pub fn backing_file(&self) -> Option<String> {
41 match self {
42 Self::Qcow2(qcow) => qcow.header.backing_file.clone(),
43 Self::Qcow1(qcow) => qcow.header.backing_file.clone(),
44 }
45 }
46
47 #[track_caller]
49 pub fn unwrap_qcow1(self) -> Qcow1 {
50 match self {
51 Self::Qcow1(qcow) => qcow,
52 _ => panic!("Expected a version 1 qcow"),
53 }
54 }
55
56 #[track_caller]
59 pub fn unwrap_qcow2(self) -> Qcow2 {
60 #[allow(unreachable_patterns)]
61 match self {
62 Self::Qcow2(qcow) => qcow,
63 _ => panic!("Expected a version 2+ qcow"),
64 }
65 }
66}