Struct marc::record::Field

source ·
pub struct Field { /* private fields */ }
Expand description

A MARC Data Field with tag, indicators, and subfields.

Implementations§

source§

impl Field

source

pub fn to_breaker(&self) -> String

source§

impl Field

source

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);
source

pub fn tag(&self) -> &str

Get the tag

source

pub fn ind1(&self) -> &str

Get the value of indicator-1, defaulting to DEFAULT_INDICATOR.

source

pub fn ind2(&self) -> &str

Get the value of indicator-2, defaulting to DEFAULT_INDICATOR.

source

pub fn subfields(&self) -> &Vec<Subfield>

Get the full list of subfields

source

pub fn subfields_mut(&mut self) -> &mut Vec<Subfield>

Get a mutable list of subfields.

source

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

Set the indicator-1 value.

  • ind - Must have the correct byte count.
source

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

Set the indicator-2 value.

  • ind - Must have the correct byte count.
source

pub fn get_subfields(&self, code: &str) -> Vec<&Subfield>

Get a list of subfields with the provided code.

source

pub fn first_subfield(&self, code: &str) -> Option<&Subfield>

source

pub fn has_subfield(&self, code: &str) -> bool

source

pub fn get_subfields_mut(&mut self, code: &str) -> Vec<&mut Subfield>

Get a mutable list of subfields with the provided code.

source

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.
source

pub fn remove_first_subfield(&mut self, code: &str) -> Option<Subfield>

Remove the first subfield with the specified code.

source

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§

source§

impl Clone for Field

source§

fn clone(&self) -> Field

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 Field

source§

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

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

impl PartialEq for Field

source§

fn eq(&self, other: &Field) -> 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 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> 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.