Skip to main content

Document

Struct Document 

Source
pub struct Document {
    pub package: Package,
    pub content: Element,
    pub styles_part: Option<Element>,
    pub styles: Styles,
    pub meta: Meta,
}
Expand description

A document read from a package: everything the three formats share.

Fields§

§package: Package

The package itself, which keeps every entry whether or not it was read here, so that writing gives back a document and not a subset of one.

§content: Element

The parsed content.xml.

§styles_part: Option<Element>

The parsed styles.xml, if the package has one.

§styles: Styles

Every style in the document, from both parts.

§meta: Meta

What the document says about itself.

Implementations§

Source§

impl Document

Source

pub fn read( bytes: &[u8], wanted: &'static [&'static str], ) -> Result<Self, Error>

Read a package and check its media type.

§Errors

The bytes are not a package, the package declares a different media type, or content.xml is absent or not well formed.

Source

pub fn body(&self) -> Option<&Element>

The office:body element, which every format has exactly one of.

Source

pub fn body_of(&self, local: &str) -> Option<&Element>

The part of the body this format keeps its content in: office:text, office:spreadsheet or office:presentation.

Source

pub fn body_path(&self, local: &str) -> Option<Vec<usize>>

Where Self::body_of is under the content root, as a path of child indices: what an editor addresses the body’s paragraphs from.

Source

pub fn name(&self, ns: &Ns, local: &str) -> Name

A name for writing into the document, in the prefix the document declares for the namespace on its content root, or the conventional one where it declares none.

Source

pub fn declares(&self, ns: &Ns) -> bool

Whether the content root declares a namespace, which is what decides whether an attribute in it may be written at all.

Source

pub fn version(&self) -> Option<&str>

The version of the format the document declares, as office:version.

Source

pub fn picture(&self, href: &str) -> Option<&[u8]>

The bytes of a picture, by the xlink:href that referred to it.

A href that names an entry of the package gives those bytes. A href that is a URL to somewhere else gives None: reaching it would be a network request, which nothing in this suite makes.

Source

pub fn write(&mut self) -> Result<Vec<u8>, Error>

Write the document back out, with the parsed parts re-serialized over the ones they were read from.

§Errors

The package could not be assembled.

Source

pub fn write_verified(&mut self) -> Result<Vec<u8>, Error>

Write the document and prove the bytes read back as the tree they were written from, which is what a save has to know before it touches the file.

The round-trip tests make the same claim over the corpus, and a person’s document is not in the corpus. One re-parse per save is the price, and the alternative is an editor that finds out it damaged a document after it has.

§Errors

The package could not be assembled, or a part came back different, in which case nothing should be written.

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 = !

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.