pub trait PackageSource {
// Required methods
fn part_names(&self) -> Result<Vec<String>>;
fn contains_part(&self, name: &str) -> Result<bool>;
fn read_part(&self, name: &str) -> Result<Option<Vec<u8>>>;
// Provided method
fn raw_archive_bytes(&self) -> Option<&[u8]> { ... }
}Expand description
Read-only access to a DOCX package (ZIP/OPC archive).
Implemented by ZipPackageSource for file/stream-backed packages and by
InMemoryPackageSource for in-memory packages used in tests.
Higher-level layers depend on this trait rather than any concrete ZIP type, which keeps the templating engine independent of storage format.
§Contract
part_namesreturns only safe part names (no path traversal).read_partreturnsNonefor unknown parts, never an error for “not found”.- Part names use forward slashes as separators and do NOT start with
/.
Required Methods§
Sourcefn part_names(&self) -> Result<Vec<String>>
fn part_names(&self) -> Result<Vec<String>>
Return the names of all parts in this package.
Implementations must filter out unsafe entry names before returning.
Sourcefn contains_part(&self, name: &str) -> Result<bool>
fn contains_part(&self, name: &str) -> Result<bool>
Return true if the named part exists in this package.
Provided Methods§
Sourcefn raw_archive_bytes(&self) -> Option<&[u8]>
fn raw_archive_bytes(&self) -> Option<&[u8]>
Return the raw bytes of the underlying archive, if available.
Returning Some allows ZipPackageWriter to copy parts verbatim
without decompressing and recompressing them. The default returns
None, which causes a safe fallback to decompress + recompress.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".