docx-templating 1.0.0

Rust library for DOCX templating with variable replacement, conditionals, and loops
Documentation
//! `PackageWriter` trait — abstract write access to a DOCX/OPC package.

use crate::Result;
use crate::package::PackageSource;

/// Write access to a DOCX package (ZIP/OPC archive).
///
/// Implemented by [`ZipPackageWriter`] for file/stream-backed output.
///
/// The typical rendering workflow:
/// 1. Call `write_part` for each modified XML part.
/// 2. Call `copy_part` for every unmodified part from the source.
/// 3. Call `finish` to flush and seal the archive.
///
/// [`ZipPackageWriter`]: crate::package::ZipPackageWriter
pub trait PackageWriter {
    /// Write raw bytes as a named part, replacing any existing content.
    ///
    /// `name` must be a safe part name (no traversal components).
    fn write_part(&mut self, name: &str, contents: &[u8]) -> Result<()>;

    /// Copy a part verbatim from `source` into this package.
    ///
    /// This is a convenience that avoids decompressing and re-compressing
    /// unchanged entries when possible.
    fn copy_part(&mut self, source: &dyn PackageSource, name: &str) -> Result<()>;

    /// Finalise and seal the archive.
    ///
    /// Must be called exactly once after all parts have been written.
    /// Dropping without calling `finish` may leave the archive incomplete.
    fn finish(self) -> Result<()>;
}