Skip to main content

Error

Enum Error 

Source
pub enum Error {
    Io(Error),
    Zip(ZipError),
    Xml(String),
    Opc(String),
    Oxml(String),
    NotFound(String),
    IndexOutOfRange(usize),
    NotImplemented(&'static str),
    Encryption(String),
    Ppt97(String),
    Other(String),
}
Expand description

库错误。所有外部接口(除特别声明外)均返回 Result<T>

变体按“来源“分类,调用方可以基于 match 决定重试 / 跳过 / 报告策略。 错误消息遵循 小写开头、句末无标点 的 Rust 标准库风格。

Variants§

§

Io(Error)

I/O 错误:文件不存在、读取失败、写入失败、权限拒绝等。

#[from] io::Error 自动派生,调用方可用 ? 直接把任意 std::io::Error 提升为本变体。

§

Zip(ZipError)

zip 压缩包错误:CRC 校验失败、条目不存在、解压错误等。

#[from] zip::result::ZipError 派生,封装 zip crate 的全部错误。

§

Xml(String)

XML 解析或序列化错误。

字符串内容应包含 出错元素名 + 上下文路径,例如 "slide layout1.xml parse: unexpected end of <p:sld> at line 42"

§

Opc(String)

OPC 包结构错误。

典型场景:

  • 缺少必要的 part(如 word/document.xml 缺失);
  • 关系链断裂(r:id 指向不存在的 target);
  • [Content_Types].xml 中缺失 Override / Default。
§

Oxml(String)

OOXML 模型错误。

典型场景:

  • 缺失必要字段(如 slideLayout 必须有 cSld);
  • 命名空间不匹配;
  • 序列化时违反 OOXML 元素顺序约束(CT_* schema 严格顺序)。
§

NotFound(String)

元素未找到:按 Id / Name / Type 查找时未命中。

§

IndexOutOfRange(usize)

索引越界:访问 Slides / Shapes 等集合时 idx >= len。

§

NotImplemented(&'static str)

不支持的功能(路线图中)。

携带 &'static str 描述功能名,便于编译期收集未实现项清单。

§

Encryption(String)

加密/解密错误。

典型场景:

  • 密码不匹配;
  • 加密算法不支持;
  • AES 密钥/IV 长度不正确;
  • 加密文件格式损坏。
§

Ppt97(String)

.ppt(PowerPoint 97-2003 二进制格式)处理错误。

典型场景:

  • OLE2/CFB 容器结构损坏;
  • PPT record 树解析失败(record header / recLen 异常);
  • 找不到必要 stream(PowerPoint Document / Current User);
  • PersistDirectoryAtom 解析失败;
  • 水印注入失败(找不到 MainMaster / PPDrawing / SpgrContainer);
  • persist 对象重排失败。

Error::Encryption 的区别:本变体专指 .ppt 二进制格式的 结构性错误;而 Encryption 侧重密钥/算法层面的失败。

§

Other(String)

其它错误。

用于临时过渡;正式错误请扩展 enum Error 的具体变体。

Implementations§

Source§

impl Error

Source

pub fn opc<S: Into<String>>(msg: S) -> Self

便捷构造:OPC 错误。

接受任何 Into<String> 的消息,避免调用方手动写 Error::Opc(s.into())

Source

pub fn oxml<S: Into<String>>(msg: S) -> Self

便捷构造:OOXML 错误。

Source

pub fn not_implemented(feature: &'static str) -> Self

便捷构造:未实现。

配合 unimplemented! 风格的早期失败语义,用于在路线图功能 调用点快速失败。

Source

pub fn encryption<S: Into<String>>(msg: S) -> Self

便捷构造:加密/解密错误。

Source

pub fn ppt97<S: Into<String>>(msg: S) -> Self

便捷构造:.ppt 97-2003 二进制格式处理错误。

用于 OLE2 容器、PPT record 树、persist 对象等结构性失败。

Trait Implementations§

Source§

impl Debug for Error

Source§

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

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

impl Display for Error

Source§

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

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

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for Error

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

ooxml_core::Error 到本 crate Error 的逐变体映射。

ooxml-core 是格式无关的公共基座,不含 PPT 97-2003 二进制格式专有的 Ppt97 变体。pptx-rs 通过本 impl 把 ooxml-core 的错误提升为本地错误, 让 ? 能在 use pptx_rs::Result 的代码中直接传播 ooxml-core 的错误。

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl From<ZipError> for Error

Source§

fn from(source: ZipError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Freeze for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V