Trait FormatCreateBuilder

Source
pub trait FormatCreateBuilder<S: Storage>: Sized {
    type DriverBuilder: FormatDriverBuilder<S>;

    const FORMAT: Format;

    // Required methods
    fn new(image: S) -> Self;
    fn size(self, size: u64) -> Self;
    fn preallocate(self, prealloc_mode: PreallocateMode) -> Self;
    async fn create(self) -> Result<()>;
    async fn create_open<G: ImplicitOpenGate<S>, F: FnOnce(S) -> Result<Self::DriverBuilder>>(
        self,
        open_gate: G,
        open_builder_fn: F,
    ) -> Result<<Self::DriverBuilder as FormatDriverBuilder<S>>::Format>;
    fn get_size(&self) -> u64;
    fn get_preallocate(&self) -> PreallocateMode;
}
Expand description

Prepares creating (formatting) an image.

There are common options for all kinds of formats, which are accessible through this trait’s methods, but there are also specialized options that depend on the format itself. Each implementation will provide such specialized methods.

See Qcow2CreateBuilder for an example implementation.

Required Associated Constants§

Source

const FORMAT: Format

Which format this is.

Required Associated Types§

Source

type DriverBuilder: FormatDriverBuilder<S>

Open builder type for this format.

Required Methods§

Source

fn new(image: S) -> Self

Prepare formatting the given image file.

Source

fn size(self, size: u64) -> Self

Set the virtual disk size.

Source

fn preallocate(self, prealloc_mode: PreallocateMode) -> Self

Set the desired preallocation mode.

Source

async fn create(self) -> Result<()>

Format the image file.

Formats the underlying image file according to the options specified in self.

This will delete any currently present data in the image!

Source

async fn create_open<G: ImplicitOpenGate<S>, F: FnOnce(S) -> Result<Self::DriverBuilder>>( self, open_gate: G, open_builder_fn: F, ) -> Result<<Self::DriverBuilder as FormatDriverBuilder<S>>::Format>

Format the image file and open it.

Same as FormatCreateBuilder::create(), but also opens the image file.

Note that the image file will always be opened as writable, regardless of whether this was set in open_builder or not. This is because formatting requires the image to be writable.

Source

fn get_size(&self) -> u64

Get the set virtual disk size.

Source

fn get_preallocate(&self) -> PreallocateMode

Get the preallocation mode.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<S: Storage + 'static> FormatCreateBuilder<S> for RawCreateBuilder<S>

Source§

impl<S: Storage + 'static, F: WrappedFormat<S> + 'static> FormatCreateBuilder<S> for Qcow2CreateBuilder<S, F>

Source§

const FORMAT: Format = Format::Qcow2

Source§

type DriverBuilder = Qcow2OpenBuilder<S, F>