Struct pica_record::primitives::OccurrenceRef
source · pub struct OccurrenceRef<'a>(/* private fields */);
Expand description
An immutable occurrence.
Implementations§
source§impl<'a> OccurrenceRef<'a>
impl<'a> OccurrenceRef<'a>
sourcepub fn new(occ: &'a str) -> Result<Self, ParsePicaError>
pub fn new(occ: &'a str) -> Result<Self, ParsePicaError>
Create a new OccurrenceRef from a string slice.
§Panics
This method panics if the occurrence is invalid.
§Example
use pica_record::primitives::OccurrenceRef;
let occurrence = OccurrenceRef::new("001")?;
assert_eq!(occurrence, "001");
sourcepub fn from_unchecked<T: AsRef<[u8]> + ?Sized>(occurrence: &'a T) -> Self
pub fn from_unchecked<T: AsRef<[u8]> + ?Sized>(occurrence: &'a T) -> Self
Create a new OccurrenceRef without checking for validity.
§Safety
The caller must ensure that the occurrence is valid.
§Example
use pica_record::primitives::OccurrenceRef;
let occurrence = OccurrenceRef::from_unchecked("001");
assert_eq!(occurrence, "001");
sourcepub fn from_bytes<B: AsRef<[u8]> + ?Sized>(
occurrence: &'a B,
) -> Result<Self, ParsePicaError>
pub fn from_bytes<B: AsRef<[u8]> + ?Sized>( occurrence: &'a B, ) -> Result<Self, ParsePicaError>
Create a new OccurrenceRef from a byte slice.
§Panics
This method panics if the occurrence is invalid.
§Example
use pica_record::primitives::OccurrenceRef;
let occurrence = OccurrenceRef::from_bytes(b"00")?;
assert_eq!(occurrence, "00");
sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Returns the OccurrenceRef as a byte slice.
§Example
use pica_record::primitives::OccurrenceRef;
let occurrence = OccurrenceRef::from_bytes(b"01")?;
assert_eq!(occurrence.as_bytes(), b"01");
sourcepub fn write_to(&self, out: &mut impl Write) -> Result<()>
pub fn write_to(&self, out: &mut impl Write) -> Result<()>
Write the OccurrenceRef into the given writer.
§Example
use std::io::Cursor;
use pica_record::primitives::OccurrenceRef;
let mut writer = Cursor::new(Vec::<u8>::new());
let occurrence = OccurrenceRef::new("01")?;
occurrence.write_to(&mut writer);
assert_eq!(String::from_utf8(writer.into_inner())?, "/01");
Trait Implementations§
source§impl<'a> Clone for OccurrenceRef<'a>
impl<'a> Clone for OccurrenceRef<'a>
source§fn clone(&self) -> OccurrenceRef<'a>
fn clone(&self) -> OccurrenceRef<'a>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<'a> Debug for OccurrenceRef<'a>
impl<'a> Debug for OccurrenceRef<'a>
source§impl From<OccurrenceRef<'_>> for Occurrence
impl From<OccurrenceRef<'_>> for Occurrence
source§fn from(occurrence: OccurrenceRef<'_>) -> Self
fn from(occurrence: OccurrenceRef<'_>) -> Self
Creates a Occurrence from a OccurrenceRef.
§Example
use pica_record::primitives::{Occurrence, OccurrenceRef};
let occ_ref = OccurrenceRef::new("001")?;
let occ = Occurrence::from(occ_ref);
assert_eq!(occ, "001");
source§impl PartialEq<Occurrence> for OccurrenceRef<'_>
impl PartialEq<Occurrence> for OccurrenceRef<'_>
source§fn eq(&self, other: &Occurrence) -> bool
fn eq(&self, other: &Occurrence) -> bool
Compares a OccurrenceRef with Occurrence.
§Example
use pica_record::primitives::{Occurrence, OccurrenceRef};
let occ_ref = OccurrenceRef::new("999")?;
let occ = Occurrence::new("999")?;
assert_eq!(occ_ref, occ);
source§impl<T: AsRef<[u8]>> PartialEq<T> for OccurrenceRef<'_>
impl<T: AsRef<[u8]>> PartialEq<T> for OccurrenceRef<'_>
source§impl<'a> PartialEq for OccurrenceRef<'a>
impl<'a> PartialEq for OccurrenceRef<'a>
source§impl<'a> PartialOrd for OccurrenceRef<'a>
impl<'a> PartialOrd for OccurrenceRef<'a>
impl<'a> Eq for OccurrenceRef<'a>
impl<'a> StructuralPartialEq for OccurrenceRef<'a>
Auto Trait Implementations§
impl<'a> Freeze for OccurrenceRef<'a>
impl<'a> RefUnwindSafe for OccurrenceRef<'a>
impl<'a> Send for OccurrenceRef<'a>
impl<'a> Sync for OccurrenceRef<'a>
impl<'a> Unpin for OccurrenceRef<'a>
impl<'a> UnwindSafe for OccurrenceRef<'a>
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
)