Trait Table

Source
pub trait Table: Sized {
    type InternalEntry: TableEntry;
    type Entry: Copy;

    const NAME: &'static str;
    const MAX_ENTRIES: usize;
Show 17 methods // Required methods fn from_data(data: Box<[Self::InternalEntry]>, header: &Header) -> Self; fn entries(&self) -> usize; fn get_ref(&self, index: usize) -> Option<&Self::InternalEntry>; fn get(&self, index: usize) -> Self::Entry; fn get_cluster(&self) -> Option<HostCluster>; fn get_offset(&self) -> Option<HostOffset>; fn set_cluster(&mut self, cluster: HostCluster); fn unset_cluster(&mut self); fn cluster_bits(&self) -> u32; fn is_modified(&self) -> bool; fn clear_modified(&self); fn set_modified(&self); // Provided methods fn byte_size(&self) -> usize { ... } fn cluster_count(&self) -> ClusterCount { ... } async fn load<S: Storage>( image: &S, header: &Header, cluster: HostCluster, entries: usize, ) -> Result<Self> { ... } async fn write<S: Storage>(&self, image: &S) -> Result<()> { ... } async fn write_entry<S: Storage>( &self, image: &S, index: usize, ) -> Result<()> { ... }
}
Expand description

Generic trait for qcow2 metadata tables (L1, L2, refcount table).

Required Associated Constants§

Source

const NAME: &'static str

User-readable struct name.

Source

const MAX_ENTRIES: usize

Maximum allowable number of entries.

Required Associated Types§

Source

type InternalEntry: TableEntry

Internal type for each table entry.

Source

type Entry: Copy

Externally visible type for each table entry.

Required Methods§

Source

fn from_data(data: Box<[Self::InternalEntry]>, header: &Header) -> Self

Create a new table with the given contents

Source

fn entries(&self) -> usize

Number of entries.

Source

fn get_ref(&self, index: usize) -> Option<&Self::InternalEntry>

Get the given entry (as reference).

Source

fn get(&self, index: usize) -> Self::Entry

Get the given entry (copied).

Source

fn get_cluster(&self) -> Option<HostCluster>

Get this table’s (first) cluster in the image file.

Source

fn get_offset(&self) -> Option<HostOffset>

Get this table’s offset in the image file.

Source

fn set_cluster(&mut self, cluster: HostCluster)

Set this table’s (first) cluster in the image file (for writing).

Source

fn unset_cluster(&mut self)

Remove the table’s association with any cluster in the image file.

Source

fn cluster_bits(&self) -> u32

Return log2 of the cluster size.

All tables store this anyway.

Source

fn is_modified(&self) -> bool

Check whether this table has been modified since it was last written.

Source

fn clear_modified(&self)

Clear the modified flag.

Source

fn set_modified(&self)

Set the modified flag.

Provided Methods§

Source

fn byte_size(&self) -> usize

Table size in bytes.

Source

fn cluster_count(&self) -> ClusterCount

Number of clusters used by this table.

Source

async fn load<S: Storage>( image: &S, header: &Header, cluster: HostCluster, entries: usize, ) -> Result<Self>

Load a table from the image file.

Source

async fn write<S: Storage>(&self, image: &S) -> Result<()>

Write a table to the image file.

Callers must ensure the table is copied, i.e. its refcount is 1.

Source

async fn write_entry<S: Storage>(&self, image: &S, index: usize) -> Result<()>

Write at least the given single (modified) entry to the image file.

Potentially writes more of the table, if alignment requirements ask for that.

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 Table for L1Table

Source§

const NAME: &'static str = "L1 table"

Source§

const MAX_ENTRIES: usize = 4_194_304usize

Source§

type InternalEntry = L1Entry

Source§

type Entry = L1Entry

Source§

impl Table for L2Table

Source§

const NAME: &'static str = "L2 table"

Source§

const MAX_ENTRIES: usize = 262_144usize

Source§

type InternalEntry = AtomicL2Entry

Source§

type Entry = L2Entry

Source§

impl Table for RefTable

Source§

const NAME: &'static str = "Refcount table"

Source§

const MAX_ENTRIES: usize = 4_194_304usize

Source§

type InternalEntry = RefTableEntry

Source§

type Entry = RefTableEntry