Skip to main content

Updates

Struct Updates 

Source
pub struct Updates { /* private fields */ }
Expand description

Updates to apply when writing a file

This struct uses a builder pattern where the default is to keep all existing metadata unchanged. Use the builder methods to explicitly specify changes.

§Example

use asset_io::Updates;

// Default: keep everything
let keep = Updates::new();

// Remove XMP, keep everything else
let no_xmp = Updates::new().remove_xmp();

// Set a new C2PA manifest store, remove XMP, keep everything else
let updates = Updates::new()
    .set_c2pa(b"new manifest store".to_vec())
    .remove_xmp();

Implementations§

Source§

impl Updates

Source

pub fn new() -> Self

Create a new Updates builder with all metadata set to keep (no changes)

This is the same as Updates::default() but more explicit.

Source

pub fn set_xmp(self, xmp: Vec<u8>) -> Self

Set XMP metadata to a new value

§Example
use asset_io::Updates;

let updates = Updates::new().set_xmp(b"<xmp>...</xmp>".to_vec());
Source

pub fn remove_xmp(self) -> Self

Remove XMP metadata

§Example
use asset_io::Updates;

let updates = Updates::new().remove_xmp();
Source

pub fn keep_xmp(self) -> Self

Keep existing XMP metadata (explicit, same as default)

§Example
use asset_io::Updates;

let updates = Updates::new().keep_xmp();
Source

pub fn set_c2pa(self, store: Vec<u8>) -> Self

Set the C2PA manifest store (a JUMBF superbox) to a new value.

The store replaces the existing one, or is added where the container’s C2PA embedding puts it. Other JUMBF, which containers such as JPEG may carry alongside, is left as it is. A container that carries JUMBF of any type tells a store by its superbox type, so there the store must have the type C2PA_STORE_TYPE.

§Example
use asset_io::Updates;

let updates = Updates::new().set_c2pa(b"manifest store".to_vec());
Source

pub fn xmp(&self) -> &MetadataUpdate

What to do with the XMP.

Source

pub fn c2pa(&self) -> &MetadataUpdate

What to do with the C2PA manifest store.

Source

pub fn is_c2pa_update(&self) -> bool

Whether the store being set is an update to the existing store; see as_update.

Source

pub fn removes_all(&self) -> bool

Whether these updates came from remove_all. A handler that has options of its own (see extension) treats an option that was not set as removed then.

Source

pub fn set_extension<T: Any + Send + Sync>(self, value: T) -> Self

Attach an option that one container defines for itself, such as the merkle boxes of ISO BMFF. One value is kept per type; a later value of the same type replaces the earlier. Containers that do not know the type ignore it. A container that defines an option usually offers builder methods that call this, so callers rarely do.

Source

pub fn extension<T: Any + Send + Sync>(&self) -> Option<&T>

The option of type T, if one was set with set_extension.

Source

pub fn clear_extension<T: Any + Send + Sync>(self) -> Self

Forget the option of type T.

Source

pub fn as_update(self) -> Self

Mark the store given to set_c2pa as an update manifest added to the existing store: set_c2pa(store).as_update(). Call it after set_c2pa; a later set_c2pa, remove_c2pa or keep_c2pa clears it.

Most containers ignore this. A container that keeps the original store apart from later additions (ISO BMFF) uses it: if the new store begins with the existing store’s manifests, byte for byte, it leaves them in place and stores only the rest as an update. Otherwise (nothing to update, or the existing manifests changed) it writes the new store as a whole. The hint is needed because a standard manifest added to a signed file extends the store in the same way, and must not be treated as an update.

Source

pub fn remove_c2pa(self) -> Self

Remove the C2PA manifest store. Other JUMBF is kept.

§Example
use asset_io::Updates;

let updates = Updates::new().remove_c2pa();
Source

pub fn keep_c2pa(self) -> Self

Keep the existing C2PA manifest store (explicit, same as default)

§Example
use asset_io::Updates;

let updates = Updates::new().keep_c2pa();
Source

pub fn keep_all() -> Self

Create updates that keep all existing metadata (no changes)

This is an alias for Updates::new() or Updates::default().

Source

pub fn remove_all() -> Self

Create updates that remove all metadata

§Example
use asset_io::Updates;

let updates = Updates::remove_all();
Source

pub fn with_xmp(xmp: Vec<u8>) -> Self

Create updates that set new XMP (legacy constructor)

Prefer using Updates::new().set_xmp(xmp) for consistency with the builder pattern.

Source

pub fn with_c2pa(store: Vec<u8>) -> Self

Create updates that set a new C2PA manifest store (legacy constructor)

Prefer using Updates::new().set_c2pa(store) for consistency with the builder pattern.

Trait Implementations§

Source§

impl BmffUpdates for Updates

Available on crate feature bmff only.
Source§

fn set_merkle(self, payloads: Vec<Vec<u8>>) -> Self

Replace the file’s merkle boxes with one box per payload. Read more
Source§

fn remove_merkle(self) -> Self

Remove the file’s merkle boxes. See set_merkle.
Source§

fn keep_merkle(self) -> Self

Keep the file’s merkle boxes (explicit, same as default).
Source§

fn merkle(&self) -> &MerkleUpdate

What to do with the merkle boxes.
Source§

impl Debug for Updates

Source§

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

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

impl Default for Updates

Source§

fn default() -> Self

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