MetadataItem

Struct MetadataItem 

Source
pub struct MetadataItem {
    pub id: Option<String>,
    pub property: String,
    pub value: String,
    pub lang: Option<String>,
    pub refined: Vec<MetadataRefinement>,
}
Expand description

Represents a metadata item in the EPUB publication

The MetadataItem structure represents a single piece of metadata from the EPUB publication. Metadata items contain information about the publication such as title, author, identifier, language, and other descriptive information.

In EPUB 3.0, metadata items can have refinements that provide additional details about the main metadata item. For example, a title metadata item might have refinements that specify it is the main title of the publication.

§Builder Methods

When the builder feature is enabled, this struct provides convenient builder methods:

use lib_epub::types::MetadataItem;

let metadata = MetadataItem::new("title", "Sample Book")
    .with_id("title-1")
    .with_lang("en")
    .build();

Fields§

§id: Option<String>

Optional unique identifier for this metadata item

Used to reference this metadata item from other elements or refinements. In EPUB 3.0, this ID is particularly important for linking with metadata refinements.

§property: String

The metadata property name

This field specifies the type of metadata this item represents. Common properties include “title”, “creator”, “identifier”, “language”, “publisher”, etc. These typically correspond to Dublin Core metadata terms.

§value: String

The metadata value

§lang: Option<String>

Optional language code for this metadata item

§refined: Vec<MetadataRefinement>

Refinements of this metadata item

In EPUB 3.x, metadata items can have associated refinements that provide additional information about the main metadata item. For example, a creator metadata item might have refinements specifying the creator’s role (author, illustrator, etc.) or file-as.

In EPUB 2.x, metadata items may contain custom attributes, which will also be parsed as refinement.

Implementations§

Source§

impl MetadataItem

Source

pub fn new(property: &str, value: &str) -> Self

Creates a new metadata item with the given property and value

Requires the builder feature.

§Parameters
  • property - The metadata property name (e.g., “title”, “creator”)
  • value - The metadata value
Source

pub fn with_id(&mut self, id: &str) -> &mut Self

Sets the ID of the metadata item

Requires the builder feature.

§Parameters
  • id - The ID to assign to this metadata item
Source

pub fn with_lang(&mut self, lang: &str) -> &mut Self

Sets the language of the metadata item

Requires the builder feature.

§Parameters
  • lang - The language code (e.g., “en”, “fr”, “zh-CN”)
Source

pub fn append_refinement(&mut self, refine: MetadataRefinement) -> &mut Self

Adds a refinement to this metadata item

Requires the builder feature.

§Parameters
  • refine - The refinement to add
§Notes
  • The metadata item must have an ID for refinements to be added.
Source

pub fn build(&self) -> Self

Builds the final metadata item

Requires the builder feature.

Trait Implementations§

Source§

impl Clone for MetadataItem

Source§

fn clone(&self) -> MetadataItem

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for MetadataItem

Source§

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

Formats the value using the given formatter. 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> Same for T

Source§

type Output = T

Should always be Self
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.