Skip to main content

OpcPackage

Struct OpcPackage 

Source
pub struct OpcPackage {
    pub parts: BTreeMap<String, Part>,
    pub content_types: ContentTypes,
}
Expand description

一个 OPC 包。

内部包含:

  • parts:所有 part 的字典(key 为 partname 字符串);
  • content_types:根 [Content_Types].xml 的强类型模型。

Fields§

§parts: BTreeMap<String, Part>

所有 part(partname → Part),按 partname 字典序排列。

§content_types: ContentTypes

ContentTypes 模型。

Implementations§

Source§

impl OpcPackage

Source

pub fn new() -> Self

构造空包(含默认 ContentTypes)。

Source

pub fn put_part(&mut self, p: Part)

放入一个 part(覆盖同名)。

在插入前会调用 Part::contribute_to,由 part 自己决定如何 更新 Content-Types(添加 override 等)。

Source

pub fn get_part(&self, partname: &str) -> Option<&Part>

取一个 part 的不可变引用。

Source

pub fn get_part_mut(&mut self, partname: &str) -> Option<&mut Part>

取一个 part 的可变引用。

Source

pub fn iter_parts(&self) -> impl Iterator<Item = &Part>

列出所有 part。

Source

pub fn part_count(&self) -> usize

part 数量。

Source

pub fn load(path: impl AsRef<Path>) -> Result<Self>

加载 .pptx(zip 文件)。

§流程
  1. 读取 [Content_Types].xml 并解析;
  2. 遍历 zip 全部条目,把非目录、非 [Content_Types].xml 的条目 装入 parts
§错误
  • Error::Io:文件读取失败;
  • Error::Zip:zip 解压失败;
  • Error::Xml[Content_Types].xml 解析失败。
Source

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

保存为 .pptx

写入顺序:先 [Content_Types].xml,再按字典序遍历所有 part。 所有条目使用 deflate 压缩 + 0o644 Unix 权限。

Source

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

写回内存 zip(用于测试)。

Trait Implementations§

Source§

impl Clone for OpcPackage

Source§

fn clone(&self) -> OpcPackage

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OpcPackage

Source§

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

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

impl Default for OpcPackage

Source§

fn default() -> OpcPackage

Returns the “default value” for a type. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.