Struct pica_record::primitives::Subfield
source · pub struct Subfield(/* private fields */);
Expand description
A mutable subfield.
Implementations§
source§impl Subfield
impl Subfield
sourcepub fn new(code: char, value: &str) -> Result<Self, ParsePicaError>
pub fn new(code: char, value: &str) -> Result<Self, ParsePicaError>
Create a new immutable PICA+ SubfieldRef.
§Example
use pica_record::primitives::Subfield;
let subfield = Subfield::new('a', "abc")?;
assert_eq!(subfield.code(), 'a');
assert_eq!(subfield.value(), "abc");
sourcepub fn code(&self) -> &SubfieldCode
pub fn code(&self) -> &SubfieldCode
Returns the code of the subfield.
§Example
use pica_record::primitives::Subfield;
let subfield = Subfield::new('X', "")?;
assert_eq!(subfield.code(), 'X');
sourcepub fn value(&self) -> &SubfieldValue
pub fn value(&self) -> &SubfieldValue
Returns the value of the subfield.
§Example
use pica_record::primitives::Subfield;
let subfield = Subfield::new('a', "abc")?;
assert_eq!(subfield.value(), b"abc");
sourcepub fn write_to(&self, out: &mut impl Write) -> Result<()>
pub fn write_to(&self, out: &mut impl Write) -> Result<()>
Write the subfield into the given writer.
§Example
use std::io::Cursor;
use pica_record::primitives::{Subfield, SubfieldRef};
let mut writer = Cursor::new(Vec::<u8>::new());
let subfield = Subfield::new('0', "123456789X")?;
subfield.write_to(&mut writer);
Trait Implementations§
source§impl From<SubfieldRef<'_>> for Subfield
impl From<SubfieldRef<'_>> for Subfield
source§fn from(subfield: SubfieldRef<'_>) -> Self
fn from(subfield: SubfieldRef<'_>) -> Self
Converts a SubfieldRef to a Subfield.
§Example
use pica_record::primitives::{Subfield, SubfieldRef};
let subfield_ref = SubfieldRef::new('0', "123456789X")?;
let subfield = Subfield::from(subfield_ref);
assert_eq!(subfield.code(), '0');
assert_eq!(subfield.value(), "123456789X");
source§impl PartialEq<Subfield> for SubfieldRef<'_>
impl PartialEq<Subfield> for SubfieldRef<'_>
impl Eq for Subfield
impl StructuralPartialEq for Subfield
Auto Trait Implementations§
impl Freeze for Subfield
impl RefUnwindSafe for Subfield
impl Send for Subfield
impl Sync for Subfield
impl Unpin for Subfield
impl UnwindSafe for Subfield
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
)