pub struct Field { /* private fields */ }
Expand description
A MARC Data Field with tag, indicators, and subfields.
Implementations§
source§impl Field
impl Field
sourcepub fn new(tag: impl Into<String>) -> Result<Self, String>
pub fn new(tag: impl Into<String>) -> Result<Self, String>
Create a Field with the provided tag.
tag
- Must have the correct byte count.
§Examples
use marc::record::Field;
let field: Field = match Field::new("245") {
Ok(f) => f,
Err(e) => panic!("Field::new() failed with: {}", e),
};
assert_eq!(field.tag(), "245");
assert_eq!(field.ind1(), " ");
assert_eq!(field.ind2(), " ");
assert_eq!(field.subfields().len(), 0);
sourcepub fn subfields_mut(&mut self) -> &mut Vec<Subfield>
pub fn subfields_mut(&mut self) -> &mut Vec<Subfield>
Get a mutable list of subfields.
sourcepub fn set_ind1(&mut self, ind: impl Into<String>) -> Result<(), String>
pub fn set_ind1(&mut self, ind: impl Into<String>) -> Result<(), String>
Set the indicator-1 value.
ind
- Must have the correct byte count.
sourcepub fn set_ind2(&mut self, ind: impl Into<String>) -> Result<(), String>
pub fn set_ind2(&mut self, ind: impl Into<String>) -> Result<(), String>
Set the indicator-2 value.
ind
- Must have the correct byte count.
sourcepub fn get_subfields(&self, code: &str) -> Vec<&Subfield>
pub fn get_subfields(&self, code: &str) -> Vec<&Subfield>
Get a list of subfields with the provided code.
pub fn first_subfield(&self, code: &str) -> Option<&Subfield>
pub fn has_subfield(&self, code: &str) -> bool
sourcepub fn get_subfields_mut(&mut self, code: &str) -> Vec<&mut Subfield>
pub fn get_subfields_mut(&mut self, code: &str) -> Vec<&mut Subfield>
Get a mutable list of subfields with the provided code.
sourcepub fn add_subfield(
&mut self,
code: impl Into<String>,
content: impl Into<String>,
) -> Result<(), String>
pub fn add_subfield( &mut self, code: impl Into<String>, content: impl Into<String>, ) -> Result<(), String>
Adds a new Subfield to this field using the provided code and content.
code
- Must have the correct byte count.
sourcepub fn remove_first_subfield(&mut self, code: &str) -> Option<Subfield>
pub fn remove_first_subfield(&mut self, code: &str) -> Option<Subfield>
Remove the first subfield with the specified code.
sourcepub fn remove_subfields(&mut self, code: &str) -> usize
pub fn remove_subfields(&mut self, code: &str) -> usize
Remove all subfields with the specified code and returns the count of removed subfields.
§Examples
use marc::record::Field;
let mut field = Field::new("505").unwrap();
let _ = field.add_subfield("t", "Chapter 1 /");
let _ = field.add_subfield("r", "Cool author --");
let _ = field.add_subfield("t", "Chapter 2.");
assert_eq!(field.subfields().len(), 3);
assert_eq!(field.remove_subfields("t"), 2);
assert_eq!(field.subfields().len(), 1);
Trait Implementations§
impl StructuralPartialEq for Field
Auto Trait Implementations§
impl Freeze for Field
impl RefUnwindSafe for Field
impl Send for Field
impl Sync for Field
impl Unpin for Field
impl UnwindSafe for Field
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> 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)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)