Skip to main content

MarcReader

Struct MarcReader 

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

Unified MARC reader with auto-detection of file format (binary ISO2709 or MARC-XML).

Internally, all data is stored as ISO2709 bytes. XML input is eagerly converted by XmlReader::parse(), so iteration always goes through BinaryReader.

Implementations§

Source§

impl MarcReader

Source

pub fn from_bytes(data: Vec<u8>) -> Result<Self, MarcError>

Auto-detect format from raw bytes and build the reader. XML data is eagerly converted to ISO2709.

Source

pub fn from_file(path: &Path) -> Result<Self, MarcError>

Read a file, auto-detect its format, and build the reader.

Source

pub fn from_binary(data: Vec<u8>) -> Self

Force binary ISO2709 format (no detection).

Source

pub fn from_xml(data: &[u8]) -> Result<Self, MarcError>

Force MARC-XML format (no detection). Parses XML eagerly into ISO2709.

Source

pub fn with_encoding(self, encoding: Encoding) -> Self

Force the encoding used when decoding raw record data. Use when the record’s declared encoding (e.g. leader byte 9 for MARC21, 100$a for UNIMARC) is wrong.

Source

pub fn clear_encoding_override(&mut self)

Clear any encoding override.

Source

pub fn source_format(&self) -> FileFormat

Returns the original file format before conversion.

Source

pub fn encoding_override(&self) -> Option<Encoding>

Returns the encoding override when set.

Source

pub fn iter(&self) -> BinaryReader<'_>

Iterate over raw ISO2709 records (with optional encoding override applied when decoding).

Source

pub fn as_bytes(&self) -> &[u8]

Raw ISO2709 bytes (useful for direct binary output).

Source

pub fn into_records(self) -> Result<Vec<Record>, MarcError>

Parse all records into the high-level semantic model. If with_encoding() was used, that encoding is applied instead of the one detected from each record.

Trait Implementations§

Source§

impl<'a> IntoIterator for &'a MarcReader

Source§

type Item = Result<RawRecordView<'a>, MarcError>

The type of the elements being iterated over.
Source§

type IntoIter = BinaryReader<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. 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 = 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.