Skip to main content

WriteBuilder

Struct WriteBuilder 

Source
pub struct WriteBuilder<'et> { /* private fields */ }
Expand description

写入构建器

Implementations§

Source§

impl<'et> WriteBuilder<'et>

Source

pub fn tag(self, tag: impl Into<String>, value: impl Into<String>) -> Self

设置标签值

Source

pub fn tag_id(self, tag: TagId, value: impl Into<String>) -> Self

设置标签值(使用 TagId)

Source

pub fn tags(self, tags: HashMap<impl Into<String>, impl Into<String>>) -> Self

设置多个标签

Source

pub fn delete(self, tag: impl Into<String>) -> Self

删除标签

Source

pub fn delete_id(self, tag: TagId) -> Self

删除标签(使用 TagId)

Source

pub fn overwrite_original(self, yes: bool) -> Self

覆盖原始文件(不创建备份)

Source

pub fn backup(self, yes: bool) -> Self

创建备份

Source

pub fn output<P: AsRef<Path>>(self, path: P) -> Self

输出到不同文件

Source

pub fn condition(self, expr: impl Into<String>) -> Self

设置条件(仅在条件满足时写入)

Source

pub fn arg(self, arg: impl Into<String>) -> Self

添加原始参数(高级用法)

Source

pub fn write_mode(self, mode: WriteMode) -> Self

设置写入模式

使用 -wm 选项设置写入/创建标签的模式

§模式
  • WriteMode::Write (w) - 写入标签(默认)
  • WriteMode::Create (c) - 仅创建标签(不修改现有标签)
  • WriteMode::WriteCreate (wc) - 写入或创建
§示例
use exiftool_rs_wrapper::{ExifTool, WriteMode};

let exiftool = ExifTool::new()?;

// 仅创建新标签,不修改现有标签
exiftool.write("photo.jpg")
    .tag("NewTag", "value")
    .write_mode(WriteMode::Create)
    .execute()?;
Source

pub fn password(self, passwd: impl Into<String>) -> Self

设置密码

使用 -password 选项处理受密码保护的文件

§安全性警告

密码将以纯文本形式传递给 ExifTool 进程。

§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

// 写入受密码保护的 PDF
exiftool.write("protected.pdf")
    .tag("Title", "New Title")
    .password("secret123")
    .execute()?;
Source

pub fn separator(self, sep: impl Into<String>) -> Self

设置列表项分隔符

使用 -sep 选项设置列表项的分隔符字符串

Source

pub fn api_option( self, opt: impl Into<String>, value: Option<impl Into<String>>, ) -> Self

设置 API 选项

使用 -api 选项设置 ExifTool API 选项

Source

pub fn user_param( self, param: impl Into<String>, value: Option<impl Into<String>>, ) -> Self

设置用户参数

使用 -userParam 选项设置用户参数

Source

pub fn ignore_minor_errors(self, yes: bool) -> Self

忽略次要错误

使用 -m 选项忽略次要错误和警告,继续处理其他文件。 这在批量处理时很有用,可以避免单个文件错误导致整个操作失败。

§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

// 批量写入时忽略次要错误
exiftool.write("photo.jpg")
    .tag("Copyright", "© 2026")
    .ignore_minor_errors(true)
    .execute()?;
Source

pub fn preserve_time(self, yes: bool) -> Self

保留文件修改时间

使用 -P 选项保留文件的原始修改时间。 默认情况下,ExifTool 会更新文件的修改时间为当前时间。

§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

// 写入元数据但保留原始修改时间
exiftool.write("photo.jpg")
    .tag("Copyright", "© 2026")
    .preserve_time(true)
    .execute()?;
Source

pub fn quiet(self, yes: bool) -> Self

静默模式

使用 -q 选项启用静默模式,减少输出信息。 可以使用多次来增加静默程度。

§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

// 静默模式下写入
exiftool.write("photo.jpg")
    .tag("Copyright", "© 2026")
    .quiet(true)
    .execute()?;
Source

pub fn zip_compression(self, yes: bool) -> Self

启用 ZIP 压缩

使用 -z 选项读写压缩的元数据信息。 某些文件格式支持压缩元数据存储。

§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

// 使用压缩写入元数据
exiftool.write("photo.jpg")
    .tag("Copyright", "© 2026")
    .zip_compression(true)
    .execute()?;
Source

pub fn fix_base(self, offset: Option<u32>) -> Self

修复 MakerNotes 偏移

使用 -F 选项修复 MakerNotes 的基准偏移。 这在处理某些损坏或格式异常的图像文件时很有用。

§参数
  • offset - 可选的偏移量修正值(以字节为单位)
§示例
use exiftool_rs_wrapper::ExifTool;

let exiftool = ExifTool::new()?;

// 自动修复 MakerNotes 偏移
exiftool.write("photo.jpg")
    .tag("Copyright", "© 2026")
    .fix_base(None)
    .execute()?;

// 指定偏移量修复
exiftool.write("photo.jpg")
    .fix_base(Some(1024))
    .execute()?;
Source

pub fn offset(self, tag: impl Into<String>, offset: impl Into<String>) -> Self

日期/时间偏移

示例: .offset("DateTimeOriginal", "+1:0:0 0:0:0") 表示增加 1 天

Source

pub fn copy_from<P: AsRef<Path>>(self, source: P) -> Self

从文件复制标签

从源文件复制所有标签到目标文件

Source

pub fn execute(self) -> Result<WriteResult>

执行写入操作

Auto Trait Implementations§

§

impl<'et> Freeze for WriteBuilder<'et>

§

impl<'et> RefUnwindSafe for WriteBuilder<'et>

§

impl<'et> Send for WriteBuilder<'et>

§

impl<'et> Sync for WriteBuilder<'et>

§

impl<'et> Unpin for WriteBuilder<'et>

§

impl<'et> UnsafeUnpin for WriteBuilder<'et>

§

impl<'et> UnwindSafe for WriteBuilder<'et>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more