Skip to main content

RenderedDocument

Struct RenderedDocument 

Source
pub struct RenderedDocument { /* private fields */ }
Expand description

A rendered DOCX document.

Wraps the generated ZIP bytes in memory, providing methods to write to a file or extract the raw bytes.

§Examples

let template = Template::from_path("template.docx")?;
let rendered = template.render(json!({"name": "Ada"}))?;

// Write to file
rendered.write_to_file("output.docx")?;

// Or get raw bytes
let bytes = rendered.as_bytes();

Implementations§

Source§

impl RenderedDocument

Source

pub fn write_to_file(self, path: impl AsRef<Path>) -> Result<()>

Write the document to a file.

§Errors

Returns error if the file cannot be written.

Source

pub fn write_to_writer<W: Write>(self, writer: W) -> Result<()>

Write the rendered DOCX bytes to any Write sink.

Consumes the RenderedDocument.

§Errors

Returns an error if writing to the sink fails.

Source

pub fn as_bytes(&self) -> &[u8] ⓘ

Get a reference to the raw DOCX bytes.

Source

pub fn into_bytes(self) -> Vec<u8> ⓘ

Consume the document and return the raw DOCX bytes.

Trait Implementations§

Source§

impl AsRef<[u8]> for RenderedDocument

Source§

fn as_ref(&self) -> &[u8] ⓘ

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Debug for RenderedDocument

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<RenderedDocument> for Vec<u8>

Source§

fn from(document: RenderedDocument) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.