Struct PubMedId
pub struct PubMedId { /* private fields */ }Expand description
A validated PubMed ID (PMID)
PMIDs are numeric identifiers for articles in the PubMed database. This type ensures that the ID is valid and provides methods for parsing, cleaning, and converting between different representations.
§Examples
use pubmed_parser::common::PubMedId;
// Parse from string
let pmid = PubMedId::parse("31978945").unwrap();
assert_eq!(pmid.as_u32(), 31978945);
assert_eq!(pmid.as_str(), "31978945");
// Parse with whitespace (automatically cleaned)
let pmid = PubMedId::parse(" 31978945 ").unwrap();
assert_eq!(pmid.as_u32(), 31978945);
// From u32
let pmid = PubMedId::from_u32(31978945);
assert_eq!(pmid.to_string(), "31978945");Implementations§
§impl PubMedId
impl PubMedId
pub fn parse(s: &str) -> Result<PubMedId, ParseError>
pub fn parse(s: &str) -> Result<PubMedId, ParseError>
Parse a PMID from a string
The input is automatically trimmed of whitespace.
§Errors
Returns ParseError::InvalidPmid if:
- The string is empty after trimming
- The string contains non-numeric characters
- The number is zero
- The number is too large to fit in a u32
§Examples
use pubmed_parser::common::PubMedId;
let pmid = PubMedId::parse("31978945").unwrap();
assert_eq!(pmid.as_u32(), 31978945);
// With whitespace
let pmid = PubMedId::parse(" 31978945 ").unwrap();
assert_eq!(pmid.as_u32(), 31978945);
// Invalid cases
assert!(PubMedId::parse("").is_err());
assert!(PubMedId::parse("abc").is_err());
assert!(PubMedId::parse("0").is_err());
assert!(PubMedId::parse("-123").is_err());pub fn try_from_u32(value: u32) -> Result<PubMedId, ParseError>
pub fn try_from_u32(value: u32) -> Result<PubMedId, ParseError>
Trait Implementations§
§impl<'de> Deserialize<'de> for PubMedId
impl<'de> Deserialize<'de> for PubMedId
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<PubMedId, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<PubMedId, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
§impl FromStr for PubMedId
impl FromStr for PubMedId
§type Err = ParseError
type Err = ParseError
The associated error which can be returned from parsing.
§impl Serialize for PubMedId
impl Serialize for PubMedId
§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 PubMedId
impl StructuralPartialEq for PubMedId
Auto Trait Implementations§
impl Freeze for PubMedId
impl RefUnwindSafe for PubMedId
impl Send for PubMedId
impl Sync for PubMedId
impl Unpin for PubMedId
impl UnwindSafe for PubMedId
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.