pub mod extract;
pub mod info;
pub mod initial;
pub mod modify;
pub mod non_standalone;
pub mod write;
pub use {extract::*, info::*, initial::*, modify::*, non_standalone::*, write::*};
cfg_if! {
if #[cfg(any(feature = "mount", doc))] {
pub mod mount;
}
}
use {
crate::{progress::ProgressCallback, sys, WimLib},
cfg_if::cfg_if,
std::{marker::PhantomData, num::NonZero, ptr::NonNull},
};
pub type ImageIndex = NonZero<u32>;
pub const ALL_IMAGES: ImageIndex = ImageIndex::new(u32::MAX).unwrap();
const fn new_image_index(n: i32) -> Option<ImageIndex> {
ImageIndex::new(n as u32)
}
pub struct Wim {
wimstruct: *mut sys::WIMStruct,
progress_callback: Option<SavedProgressCallback>,
_wimlib: WimLib,
}
impl Wim {
pub fn select_image(&self, index: ImageIndex) -> Image {
Image {
index,
wimstruct: self.wimstruct,
_borrows_wim: PhantomData,
}
}
pub fn select_all_images(&self) -> Image {
Image {
index: ALL_IMAGES,
wimstruct: self.wimstruct,
_borrows_wim: PhantomData,
}
}
}
impl Drop for Wim {
fn drop(&mut self) {
unsafe {
sys::wimlib_free(self.wimstruct);
}
}
}
struct SavedProgressCallback(NonNull<*mut ProgressCallback>);
impl Drop for SavedProgressCallback {
fn drop(&mut self) {
unsafe {
let boxed_ptr = Box::from_raw(self.0.as_ptr());
let _ = Box::from_raw(*boxed_ptr);
}
}
}
pub struct Image<'a> {
wimstruct: *mut sys::WIMStruct,
index: ImageIndex,
_borrows_wim: PhantomData<&'a Wim>,
}
impl Image<'_> {
fn ffi_index(&self) -> i32 {
self.index.get() as i32
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(i32)]
#[non_exhaustive]
pub enum CompressionType {
None = sys::wimlib_compression_type_WIMLIB_COMPRESSION_TYPE_NONE as _,
Xpress = sys::wimlib_compression_type_WIMLIB_COMPRESSION_TYPE_XPRESS as _,
Lzx = sys::wimlib_compression_type_WIMLIB_COMPRESSION_TYPE_LZX as _,
Lzms = sys::wimlib_compression_type_WIMLIB_COMPRESSION_TYPE_LZMS as _,
#[doc(hidden)]
__Unknown = -1,
}
impl CompressionType {
pub fn from_raw(val: i32) -> Self {
match val {
0 => Self::None,
1 => Self::Xpress,
2 => Self::Lzx,
3 => Self::Lzms,
_ => Self::__Unknown,
}
}
}