Skip to main content

OfdPackage

Struct OfdPackage 

Source
pub struct OfdPackage<R> { /* private fields */ }
Expand description

OFD 包,封装一个 ZIP 归档。

范型参数 R 为底层数据源,需实现 Read + Seek, 常见为 std::fs::Filestd::io::Cursor

Implementations§

Source§

impl OfdPackage<File>

Source

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

从文件系统路径打开一个 OFD 包。

Source§

impl<R: Read + Seek> OfdPackage<R>

Source

pub fn new(reader: R) -> Result<Self>

基于任意 Read + Seek 数据源创建 OFD 包。

Source

pub fn read(&mut self, path: &str) -> Result<Vec<u8>>

读取包内指定条目的原始字节。

path 允许以 / 开头,内部会归一化为 ZIP 条目名。

Source

pub fn read_to_string(&mut self, path: &str) -> Result<String>

读取包内指定条目为 UTF-8 文本。

Source

pub fn parse<T: DeserializeOwned>(&mut self, path: &str) -> Result<T>

读取并将包内 XML 条目反序列化为数据模型 T

Source

pub fn contains(&self, path: &str) -> bool

判断包内是否存在指定条目。

Source

pub fn entries(&self) -> Vec<String>

返回包内所有条目名。

Source

pub fn len(&self) -> usize

包内条目数量。

Source

pub fn is_empty(&self) -> bool

包是否为空。

Auto Trait Implementations§

§

impl<R> Freeze for OfdPackage<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for OfdPackage<R>
where R: RefUnwindSafe,

§

impl<R> Send for OfdPackage<R>
where R: Send,

§

impl<R> Sync for OfdPackage<R>
where R: Sync,

§

impl<R> Unpin for OfdPackage<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for OfdPackage<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for OfdPackage<R>
where R: UnwindSafe,

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, 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.