pub struct Subfield { /* private fields */ }
Expand description
A single subfield code + value pair
Implementations§
source§impl Subfield
impl Subfield
sourcepub fn new(
code: impl Into<String>,
content: impl Into<String>,
) -> Result<Self, String>
pub fn new( code: impl Into<String>, content: impl Into<String>, ) -> Result<Self, String>
Create a Subfield with the provided code and content.
code
- Must have the correct byte count.
§Examples
use marc::Subfield;
let subfield: Subfield = match Subfield::new("a", "Στη σκιά της πεταλούδας") {
Ok(sf) => sf,
Err(e) => panic!("Subfield::new() failed with: {}", e),
};
assert_eq!(subfield.content(), "Στη σκιά της πεταλούδας");
ⓘ
use marc::Subfield;
Subfield::new("🦋", "Στη σκιά της πεταλούδας").unwrap();
sourcepub fn set_content(&mut self, content: impl Into<String>)
pub fn set_content(&mut self, content: impl Into<String>)
Set the Subfield content.
§Examples
use marc::Subfield;
let mut subfield: Subfield = Subfield::new("a", "potato").unwrap();
subfield.set_content("cheese");
assert_eq!(subfield.content(), "cheese");
sourcepub fn code(&self) -> &str
pub fn code(&self) -> &str
Get the Subfield code.
§Examples
use marc::Subfield;
let subfield: Subfield = Subfield::new("a", "potato").unwrap();
assert_eq!(subfield.code(), "a");
sourcepub fn set_code(&mut self, code: impl Into<String>) -> Result<(), String>
pub fn set_code(&mut self, code: impl Into<String>) -> Result<(), String>
Set the Subfield code.
§Examples
use marc::Subfield;
let mut subfield: Subfield = Subfield::new("a", "potato").unwrap();
subfield.set_code("q");
assert_eq!(subfield.code(), "q");
ⓘ
use marc::Subfield;
let mut subfield: Subfield = Subfield::new("a", "potato").unwrap();
subfield.set_code("🥔").unwrap();
Trait Implementations§
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
)