Skip to main content

DocxReader

Struct DocxReader 

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

A streaming DOCX reader that implements EventSource.

DocxReader parses a DOCX archive and emits DocSpec events one at a time. <w:p> paragraphs, <w:t> text, <w:br> line breaks, <w:tab> tabs, and table elements (<w:tbl>, <w:tr>, <w:tc>) are recognized; all other elements are silently ignored.

§Streaming

The reader streams document.xml event by event using constant memory. _rels/.rels and word/_rels/document.xml.rels are both fully read into memory at package-open time (typical combined size < 10 KB). The internal event queue remains bounded regardless of document size or hyperlink count.

§Errors

Returns Error::Io for I/O failures and Error::Parse for malformed archives or XML.

Implementations§

Source§

impl DocxReader

Source

pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self>

Creates a DocxReader from a file path.

§Errors

Returns Error::Io if the file cannot be opened. See from_reader for additional error conditions.

Source

pub fn from_reader<R: Read + Seek + Send + 'static>(reader: R) -> Result<Self>

Creates a DocxReader from any Read + Seek source.

The reader must be positioned at the start of a valid DOCX (ZIP) archive.

§Errors

Returns Error::Parse if the input is not a valid ZIP archive, if _rels/.rels is missing or malformed, or if the document target entry cannot be opened. Returns Error::Io for I/O failures.

Trait Implementations§

Source§

impl Debug for DocxReader

Source§

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

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

impl EventSource for DocxReader

Source§

fn next_event(&mut self) -> Result<Option<Event>>

Returns the next event from the stream, or None if the stream has ended. Read more

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.