Struct marc::record::Record

source ·
pub struct Record { /* private fields */ }

Implementations§

source§

impl Record

source

pub fn from_binary_file(filename: &str) -> Result<BinaryRecordIterator, String>

Returns an iterator over MARC records produced from a binary file.

source

pub fn from_binary(rec_bytes: &[u8]) -> Result<Record, String>

source

pub fn to_binary(&self) -> Result<Vec<u8>, String>

Generates the binary form of a MARC record as a vector of bytes.

§Examples
use marc::Record;
let mut my_record = Record::new();
my_record
    .add_data_field("245")
    .unwrap()
    .add_subfield("a", "My favorite book")
    .unwrap();
assert_eq!(
    my_record.to_binary().unwrap(),
    "00059       00037       245002100000\x1E  \x1FaMy favorite book\x1E\x1D".as_bytes()
);
source§

impl Record

source

pub fn to_breaker(&self) -> String

Creates the MARC Breaker representation of this record as a String.

source

pub fn from_breaker(breaker: &str) -> Result<Self, String>

Creates a new MARC Record from a MARC Breaker string.

source§

impl Record

source

pub fn new() -> Self

Create a new Record with a default leader and no content.

source

pub fn leader(&self) -> &str

Get the leader as a string.

source

pub fn set_leader(&mut self, leader: impl Into<String>) -> Result<(), String>

Apply a leader value.

Returns Err if the value is not composed of the correct number of bytes.

§Examples
use marc::record::Record;
let mut record = Record::default();
assert!(record.set_leader("too short").is_err());
assert!(record.set_leader("just right              ").is_ok());
source

pub fn set_leader_bytes(&mut self, bytes: &[u8]) -> Result<(), String>

Apply a leader value from a set of bytes

Returns Err if the value is not composed of the correct number of bytes.

§Examples
use marc::record::Record;
let mut record = Record::default();
assert!(record.set_leader_bytes("too short".as_bytes()).is_err());
assert!(record.set_leader_bytes("just right              ".as_bytes()).is_ok());
source

pub fn control_fields(&self) -> &Vec<Controlfield>

Get the full list of control fields.

source

pub fn control_fields_mut(&mut self) -> &mut Vec<Controlfield>

Get the full list of control fields, mutable.

source

pub fn fields(&self) -> &Vec<Field>

Get the full list of fields.

source

pub fn fields_mut(&mut self) -> &mut Vec<Field>

Get the full list of fields, mutable.

source

pub fn get_control_fields(&self, tag: &str) -> Vec<&Controlfield>

Return a list of control fields with the provided tag.

source

pub fn get_fields(&self, tag: &str) -> Vec<&Field>

Return a list of fields with the provided tag.

source

pub fn get_fields_mut(&mut self, tag: &str) -> Vec<&mut Field>

Return a mutable list of fields with the provided tag.

source

pub fn add_control_field( &mut self, tag: &str, content: &str, ) -> Result<(), String>

Add a new control field with the provided tag and content and insert it in tag order.

Controlfields are those with tag 001 .. 009

Err if the tag is invalid.

§Examples
use marc::record::Record;
let mut record = Record::default();
assert!(record.add_control_field("011", "foo").is_err());
assert!(record.add_control_field("002", "bar").is_ok());
assert!(record.add_control_field("001", "bar").is_ok());

// should be sorted by tag.
assert_eq!(record.control_fields()[0].tag(), "001");
source

pub fn insert_control_field(&mut self, field: Controlfield)

source

pub fn insert_field(&mut self, field: Field) -> usize

Insert a data field in tag order

source

pub fn add_data_field( &mut self, tag: impl Into<String>, ) -> Result<&mut Field, String>

Create a new Field with the provided tag, insert it into the record in tag order, then return a mut ref to the new field.

§Examples
use marc::record::Record;
let mut record = Record::default();
assert!(record.add_data_field("245").is_ok());
assert!(record.add_data_field("240").is_ok());
assert!(record.add_data_field("1234").is_err());

assert_eq!(record.fields()[0].tag(), "240");
source

pub fn get_values(&self, tag: &str, sfcode: &str) -> Vec<&str>

Returns a list of values for the specified tag and subfield.

§Examples
use marc::record::Record;
let mut record = Record::default();
let field = record.add_data_field("650").expect("added field");
field.add_subfield("a", "foo");
field.add_subfield("a", "bar");

let field = record.add_data_field("650").expect("added field");
field.add_subfield("a", "baz");

let values = record.get_values("650", "a");

assert_eq!(values.len(), 3);
assert_eq!(values[1], "bar");
source

pub fn remove_control_fields(&mut self, tag: &str)

Remove all occurrences of control fields with the provided tag.

source

pub fn remove_fields(&mut self, tag: &str)

Remove all occurrences of fields with the provided tag.

source§

impl Record

source

pub fn from_xml_file(filename: &str) -> Result<XmlRecordIterator, String>

Returns an iterator over the XML file which emits Records.

source

pub fn from_xml(xml: &str) -> XmlRecordIterator

Returns an iterator over the XML string which emits Records.

source

pub fn to_xml(&self) -> Result<String, String>

Creates the XML representation of a MARC record as a String.

source

pub fn to_xml_formatted(&self) -> Result<String, String>

Creates the XML representation of a MARC record as a formatted string using 2-space indentation.

source

pub fn to_xml_ops(&self, options: &XmlOptions) -> Result<String, String>

Trait Implementations§

source§

impl Clone for Record

source§

fn clone(&self) -> Record

Returns a copy 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 Record

source§

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

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

impl Default for Record

A MARC record with leader, control fields, and data fields.

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl PartialEq for Record

source§

fn eq(&self, other: &Record) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for Record

Auto Trait Implementations§

§

impl Freeze for Record

§

impl RefUnwindSafe for Record

§

impl Send for Record

§

impl Sync for Record

§

impl Unpin for Record

§

impl UnwindSafe for Record

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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

§

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

§

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

§

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.