pub struct Record { /* private fields */ }
Implementations§
source§impl Record
impl Record
sourcepub fn from_binary_file(filename: &str) -> Result<BinaryRecordIterator, String>
pub fn from_binary_file(filename: &str) -> Result<BinaryRecordIterator, String>
Returns an iterator over MARC records produced from a binary file.
sourcepub fn from_binary(rec_bytes: &[u8]) -> Result<Record, String>
pub fn from_binary(rec_bytes: &[u8]) -> Result<Record, String>
Creates a single MARC Record from a series of bytes.
§References
sourcepub fn to_binary(&self) -> Result<Vec<u8>, String>
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
impl Record
sourcepub fn to_breaker(&self) -> String
pub fn to_breaker(&self) -> String
Creates the MARC Breaker representation of this record as a String.
sourcepub fn from_breaker(breaker: &str) -> Result<Self, String>
pub fn from_breaker(breaker: &str) -> Result<Self, String>
Creates a new MARC Record from a MARC Breaker string.
source§impl Record
impl Record
sourcepub fn set_leader(&mut self, leader: impl Into<String>) -> Result<(), String>
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());
sourcepub fn set_leader_bytes(&mut self, bytes: &[u8]) -> Result<(), String>
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());
sourcepub fn control_fields(&self) -> &Vec<Controlfield>
pub fn control_fields(&self) -> &Vec<Controlfield>
Get the full list of control fields.
sourcepub fn control_fields_mut(&mut self) -> &mut Vec<Controlfield>
pub fn control_fields_mut(&mut self) -> &mut Vec<Controlfield>
Get the full list of control fields, mutable.
sourcepub fn fields_mut(&mut self) -> &mut Vec<Field>
pub fn fields_mut(&mut self) -> &mut Vec<Field>
Get the full list of fields, mutable.
sourcepub fn get_control_fields(&self, tag: &str) -> Vec<&Controlfield>
pub fn get_control_fields(&self, tag: &str) -> Vec<&Controlfield>
Return a list of control fields with the provided tag.
sourcepub fn get_fields(&self, tag: &str) -> Vec<&Field>
pub fn get_fields(&self, tag: &str) -> Vec<&Field>
Return a list of fields with the provided tag.
sourcepub fn get_fields_mut(&mut self, tag: &str) -> Vec<&mut Field>
pub fn get_fields_mut(&mut self, tag: &str) -> Vec<&mut Field>
Return a mutable list of fields with the provided tag.
sourcepub fn add_control_field(
&mut self,
tag: &str,
content: &str,
) -> Result<(), String>
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");
pub fn insert_control_field(&mut self, field: Controlfield)
sourcepub fn insert_field(&mut self, field: Field) -> usize
pub fn insert_field(&mut self, field: Field) -> usize
Insert a data field in tag order
sourcepub fn add_data_field(
&mut self,
tag: impl Into<String>,
) -> Result<&mut Field, String>
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");
sourcepub fn get_values(&self, tag: &str, sfcode: &str) -> Vec<&str>
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");
sourcepub fn remove_control_fields(&mut self, tag: &str)
pub fn remove_control_fields(&mut self, tag: &str)
Remove all occurrences of control fields with the provided tag.
sourcepub fn remove_fields(&mut self, tag: &str)
pub fn remove_fields(&mut self, tag: &str)
Remove all occurrences of fields with the provided tag.
source§impl Record
impl Record
sourcepub fn from_xml_file(filename: &str) -> Result<XmlRecordIterator, String>
pub fn from_xml_file(filename: &str) -> Result<XmlRecordIterator, String>
Returns an iterator over the XML file which emits Records.
sourcepub fn from_xml(xml: &str) -> XmlRecordIterator ⓘ
pub fn from_xml(xml: &str) -> XmlRecordIterator ⓘ
Returns an iterator over the XML string which emits Records.
sourcepub fn to_xml(&self) -> Result<String, String>
pub fn to_xml(&self) -> Result<String, String>
Creates the XML representation of a MARC record as a String.
sourcepub fn to_xml_formatted(&self) -> Result<String, String>
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.
pub fn to_xml_ops(&self, options: &XmlOptions) -> Result<String, String>
Trait Implementations§
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> 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)