Skip to main content

BundleSource

Trait BundleSource 

Source
pub trait BundleSource: Send + Sync {
    // Required methods
    fn read_artifact(&self, name: &str) -> Result<Vec<u8>, BundleSourceError>;
    fn list_artifacts(&self) -> Result<Vec<String>, BundleSourceError>;
}
Expand description

Re-export of the full boot surface (D-11) so Shape A/B consumers register a served workbook WITHOUT ever naming pmcp-workbook-runtime: the BundleSource trait + its on-disk impl, the fail-closed loader entry point, and both error types. The EmbeddedSource impl is re-exported separately under the workbook-embedded feature (it needs the runtime’s embedded include_dir support). Raw-byte access to a single bundle’s members.

This trait is the WBSV-08 boundary (threat T-92-03): it exposes ONLY bytes, never a parsed bundle, so no impl can bypass the shared crate::bundle_loader::load integrity gate. It is Send + Sync so the served binary can hold an Arc<dyn BundleSource> across handler tasks, and it is object-safe (both methods take &self, no generics) so Box<dyn BundleSource> works.

§Example

A minimal in-memory source — the doctest defines a LOCAL dummy impl, never a downstream crate, so there is no circular doctest dependency.

use pmcp_workbook_runtime::{BundleSource, BundleSourceError};

struct OneMember;

impl BundleSource for OneMember {
    fn read_artifact(&self, name: &str) -> Result<Vec<u8>, BundleSourceError> {
        if name == "manifest.json" {
            Ok(b"{}".to_vec())
        } else {
            Err(BundleSourceError::NotFound { member: name.to_string() })
        }
    }
    fn list_artifacts(&self) -> Result<Vec<String>, BundleSourceError> {
        Ok(vec!["manifest.json".to_string()])
    }
}

let src = OneMember;
assert_eq!(src.read_artifact("manifest.json").unwrap(), b"{}");
assert!(src.read_artifact("missing.json").is_err());

Required Methods§

Source

fn read_artifact(&self, name: &str) -> Result<Vec<u8>, BundleSourceError>

Return the EXACT bytes of the member named name (a bundle-relative path such as "manifest.json" or "evidence/changelog.json").

§Errors

Returns BundleSourceError::NotFound when no such member exists, or BundleSourceError::Io when the underlying read fails.

Source

fn list_artifacts(&self) -> Result<Vec<String>, BundleSourceError>

Return the SORTED list of every member’s bundle-relative path (including nested members like "evidence/changelog.json").

The loader uses this to enforce its fail-closed membership policy, so the list MUST be complete and sorted for a stable diagnostic.

§Errors

Returns BundleSourceError::Io when the member set cannot be enumerated.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl BundleSource for EmbeddedSource

Available on crate feature embedded only.
Source§

impl BundleSource for LocalDirSource