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>
impl<W: Write> MarcWriter<W>
Sourcepub fn new(writer: W) -> Self
pub fn new(writer: W) -> Self
Create a new MARC writer.
§Arguments
writer- Any destination implementingstd::io::Write
§Examples
use mrrc::MarcWriter;
let buffer = Vec::new();
let writer = MarcWriter::new(buffer);Sourcepub fn write_record(&mut self, record: &Record) -> Result<()>
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
Sourcepub fn finish(&mut self) -> Result<()>
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.
Sourcepub fn records_written(&self) -> usize
pub fn records_written(&self) -> usize
Returns the number of records written so far.
Trait Implementations§
Source§impl<W: Write + Debug> FormatWriter for MarcWriter<W>
impl<W: Write + Debug> FormatWriter for MarcWriter<W>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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