Struct PmcId
pub struct PmcId { /* private fields */ }Expand description
A validated PubMed Central ID (PMC ID)
PMC IDs are identifiers for full-text articles in the PMC database. They consist of the prefix “PMC” followed by numeric digits. This type ensures that the ID is valid and provides methods for parsing, cleaning, and normalizing the ID format.
§Examples
use pubmed_parser::common::PmcId;
// Parse with PMC prefix
let pmcid = PmcId::parse("PMC7906746").unwrap();
assert_eq!(pmcid.as_str(), "PMC7906746");
assert_eq!(pmcid.numeric_part(), 7906746);
// Parse without PMC prefix (automatically added)
let pmcid = PmcId::parse("7906746").unwrap();
assert_eq!(pmcid.as_str(), "PMC7906746");
// With whitespace (automatically cleaned)
let pmcid = PmcId::parse(" PMC7906746 ").unwrap();
assert_eq!(pmcid.as_str(), "PMC7906746");Implementations§
§impl PmcId
impl PmcId
pub fn parse(s: &str) -> Result<PmcId, ParseError>
pub fn parse(s: &str) -> Result<PmcId, ParseError>
Parse a PMC ID from a string
The input is automatically trimmed of whitespace and the “PMC” prefix is added if not present. Case-insensitive parsing is supported.
§Errors
Returns ParseError::InvalidPmcid if:
- The string is empty after trimming
- The numeric part contains non-numeric characters
- The numeric part is zero
- The number is too large to fit in a u32
§Examples
use pubmed_parser::common::PmcId;
// With PMC prefix
let pmcid = PmcId::parse("PMC7906746").unwrap();
assert_eq!(pmcid.as_str(), "PMC7906746");
// Without PMC prefix
let pmcid = PmcId::parse("7906746").unwrap();
assert_eq!(pmcid.as_str(), "PMC7906746");
// Case insensitive
let pmcid = PmcId::parse("pmc7906746").unwrap();
assert_eq!(pmcid.as_str(), "PMC7906746");
// With whitespace
let pmcid = PmcId::parse(" PMC7906746 ").unwrap();
assert_eq!(pmcid.as_str(), "PMC7906746");
// Invalid cases
assert!(PmcId::parse("").is_err());
assert!(PmcId::parse("PMC").is_err());
assert!(PmcId::parse("PMC0").is_err());
assert!(PmcId::parse("PMCabc").is_err());pub fn try_from_u32(value: u32) -> Result<PmcId, ParseError>
pub fn try_from_u32(value: u32) -> Result<PmcId, ParseError>
pub fn as_str(&self) -> String
pub fn as_str(&self) -> String
Get the full PMC ID as a string (with “PMC” prefix)
§Examples
use pubmed_parser::common::PmcId;
let pmcid = PmcId::from_u32(7906746);
assert_eq!(pmcid.as_str(), "PMC7906746");pub fn numeric_part(&self) -> u32
pub fn numeric_part(&self) -> u32
Get the numeric part of the PMC ID (without “PMC” prefix)
§Examples
use pubmed_parser::common::PmcId;
let pmcid = PmcId::parse("PMC7906746").unwrap();
assert_eq!(pmcid.numeric_part(), 7906746);pub fn numeric_part_str(&self) -> String
pub fn numeric_part_str(&self) -> String
Get the numeric part as a string (without “PMC” prefix)
§Examples
use pubmed_parser::common::PmcId;
let pmcid = PmcId::parse("PMC7906746").unwrap();
assert_eq!(pmcid.numeric_part_str(), "7906746");Trait Implementations§
§impl<'de> Deserialize<'de> for PmcId
impl<'de> Deserialize<'de> for PmcId
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<PmcId, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<PmcId, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
§impl FromStr for PmcId
impl FromStr for PmcId
§type Err = ParseError
type Err = ParseError
The associated error which can be returned from parsing.
§impl Serialize for PmcId
impl Serialize for PmcId
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Eq for PmcId
impl StructuralPartialEq for PmcId
Auto Trait Implementations§
impl Freeze for PmcId
impl RefUnwindSafe for PmcId
impl Send for PmcId
impl Sync for PmcId
impl Unpin for PmcId
impl UnwindSafe for PmcId
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,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.