Module webc::compat

source ·
Expand description

A compatibility layer for dealing with different versions of the WEBC binary format.

The Container provides an abstraction over the various WEBC versions this crate can handle. As such, it tries to cater to the lowest common denominator and favors portability over performance or power.

In general, errors that occur during lazy operations won’t be accessible to the user.

If more flexibility is required, consider using crate::detect() and instantiating a compatible parser directly.

use webc::{
    compat::Container,
    Version,
    v2::read::OwnedReader,
    v1::{ParseOptions, WebC},
};
let bytes: &[u8] = b"...";

match webc::detect(bytes) {
    Ok(Version::V1) => {
        let options = ParseOptions::default();
        let webc = WebC::parse(bytes, &options).unwrap();
        if let Some(signature) = webc.signature {
            println!("Package signature: {:?}", signature);
        }
    }
    Ok(Version::V2) => {
        let webc = OwnedReader::parse(bytes).unwrap();
        let index = webc.index();
        let signature = &index.signature;
        if !signature.is_none() {
            println!("Package signature: {signature:?}");
        }
    }
    Ok(other) => todo!("Unsupported version, {other}"),
    Err(e) => todo!("An error occurred: {e}"),
}

Structs

  • A version-agnostic read-only WEBC container.
  • Owned bytes that can be cheaply copied and shared around.
  • A WEBC volume.

Enums