Skip to main content

DocxTemplate

Trait DocxTemplate 

Source
pub trait DocxTemplate {
    // Required methods
    fn template_path(&self) -> &Path;
    fn replacements(&self) -> Vec<(&str, &str)>;
    fn to_bytes(&self) -> Result<Vec<u8>, TemplateError>;

    // Provided method
    fn save(&self, path: &Path) -> Result<(), TemplateError> { ... }
}
Expand description

Trait implemented by all generated template structs.

Enables polymorphic use of templates via &dyn DocxTemplate or generics:

use docxide_template::DocxTemplate;

fn process(template: &dyn DocxTemplate) -> Result<Vec<u8>, docxide_template::TemplateError> {
    template.to_bytes()
}

Required Methods§

Source

fn template_path(&self) -> &Path

Returns the filesystem path to the original .docx template.

Source

fn replacements(&self) -> Vec<(&str, &str)>

Returns the list of (placeholder, value) pairs for substitution.

Source

fn to_bytes(&self) -> Result<Vec<u8>, TemplateError>

Produces the filled-in .docx as an in-memory byte vector.

Provided Methods§

Source

fn save(&self, path: &Path) -> Result<(), TemplateError>

Writes the filled-in .docx to the given path.

Creates parent directories if they do not exist. The path is used as-is — callers should include the .docx extension.

Implementors§