Skip to main content

MarcWriter

Struct MarcWriter 

Source
pub struct MarcWriter<W: Write> { /* private fields */ }
Expand description

Writer for ISO 2709 binary MARC format.

MarcWriter serializes Record instances to ISO 2709 binary format. Records are written one at a time to any destination implementing std::io::Write.

§Examples

use mrrc::{MarcWriter, Record, Leader};

let mut buffer = Vec::new();
{
    let mut writer = MarcWriter::new(&mut buffer);
    let record = Record::new(Leader::default());
    writer.write_record(&record)?;
}

Implementations§

Source§

impl<W: Write> MarcWriter<W>

Source

pub fn new(writer: W) -> Self

Create a new MARC writer.

§Arguments
§Examples
use mrrc::MarcWriter;
let buffer = Vec::new();
let writer = MarcWriter::new(buffer);
Source

pub fn write_record(&mut self, record: &Record) -> Result<()>

Write a single MARC record.

Serializes the record to ISO 2709 binary format and writes it to the underlying writer.

§Arguments
  • record - The record to write
§Examples
use mrrc::{MarcWriter, Record, Field, Leader};

let mut buffer = Vec::new();
{
    let mut writer = MarcWriter::new(&mut buffer);
    let mut record = Record::new(Leader::default());
    let mut field = Field::new("245".to_string(), '1', '0');
    field.add_subfield('a', "Title".to_string());
    record.add_field(field);
    writer.write_record(&record)?;
}
§Errors

Returns an error if:

  • The record structure is invalid
  • An I/O error occurs during writing
Source

pub fn finish(&mut self) -> Result<()>

Flush the writer and mark it as finished.

After calling finish, no more records can be written.

§Errors

Returns an error if flushing the underlying writer fails.

Source

pub fn records_written(&self) -> usize

Returns the number of records written so far.

Trait Implementations§

Source§

impl<W: Debug + Write> Debug for MarcWriter<W>

Source§

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

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

impl<W: Write + Debug> FormatWriter for MarcWriter<W>

Source§

fn write_record(&mut self, record: &Record) -> Result<()>

Write a single record to the output. Read more
Source§

fn finish(&mut self) -> Result<()>

Finish writing and flush any buffered data. Read more
Source§

fn records_written(&self) -> Option<usize>

Returns the number of records written so far. Read more
Source§

fn write_batch(&mut self, records: &[Record]) -> Result<()>

Write multiple records to the output. Read more

Auto Trait Implementations§

§

impl<W> Freeze for MarcWriter<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for MarcWriter<W>
where W: RefUnwindSafe,

§

impl<W> Send for MarcWriter<W>
where W: Send,

§

impl<W> Sync for MarcWriter<W>
where W: Sync,

§

impl<W> Unpin for MarcWriter<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for MarcWriter<W>
where W: UnsafeUnpin,

§

impl<W> UnwindSafe for MarcWriter<W>
where W: 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<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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V