pub struct ArticleId<'a> { /* private fields */ }Expand description
A unique identifier for articles published on arXiv.org
See also: Official arXiv.org documentation
§Examples
use arxiv::ArticleId;
let id = ArticleId::try_from("arXiv:2001.00001");
assert!(id.is_ok());Implementations§
Source§impl<'a> ArticleId<'a>
impl<'a> ArticleId<'a>
pub const MIN_YEAR: i16 = 2_007i16
pub const MAX_YEAR: i16 = 2_099i16
pub const MIN_NUM_DIGITS: usize = 4usize
pub const MAX_NUM_DIGITS: usize = 5usize
Sourcepub const fn new(
year: i16,
month: i8,
number: &'a str,
version: ArticleVersion,
) -> Self
pub const fn new( year: i16, month: i8, number: &'a str, version: ArticleVersion, ) -> Self
This allows manually creating an ArticleId from the given components without any
validation. Only do this if you have already verified that the components are valid.
§Safety
- The year is between the inclusive range of [2007, 2009].
- The month is between the inclusive range of [1, 12].
- The unique number string only contains 4 to 5 ASCII digits.
§Examples
use arxiv::{ArticleId, ArticleVersion};
let id = ArticleId::new(2011, 1, "00001", ArticleVersion::Num(1));Sourcepub const fn new_latest(year: i16, month: i8, id: &'a str) -> Self
pub const fn new_latest(year: i16, month: i8, id: &'a str) -> Self
This allows manually creating an ArticleId from the given components without any version
(assuming it is the latest version). Only do this if you have already verified that the
components are valid:
- The year is between the inclusive range of [2007, 2009].
- The month is between the inclusive range of [1, 12].
- The unique number string only contains 4 to 5 ASCII digits.
§Examples
use arxiv::{ArticleId, ArticleVersion};
let id = ArticleId::new_latest(2011, 1, "00001");Sourcepub const fn new_versioned(
year: i16,
month: i8,
id: &'a str,
version: u8,
) -> Self
pub const fn new_versioned( year: i16, month: i8, id: &'a str, version: u8, ) -> Self
This allows manually creating an ArticleId from the given components with a specific version.
Only do this if you have already verified that the components are valid:
- The year is between the inclusive range of [2007, 2009].
- The month is between the inclusive range of [1, 12].
- The unique number string only contains 4 to 5 ASCII digits.
§Examples
use arxiv::{ArticleId, ArticleVersion};
let id = ArticleId::new_versioned(2011, 1, "00001", 1);
assert_eq!(id.version(), ArticleVersion::Num(1));Sourcepub fn try_new(
year: i16,
month: i8,
number: &'a str,
version: ArticleVersion,
) -> ArticleIdResult<'a>
pub fn try_new( year: i16, month: i8, number: &'a str, version: ArticleVersion, ) -> ArticleIdResult<'a>
This allows manually creating an ArticleId from the given components with a version, and
will also validate each component for correctness. If any component is invalid, it will return
an ArticleIdError.
§Examples
use arxiv::{ArticleId, ArticleVersion};
let id = ArticleId::try_new(2011, 1, "00001", ArticleVersion::Num(1));
assert!(id.is_ok());Sourcepub fn try_latest(year: i16, month: i8, number: &'a str) -> ArticleIdResult<'a>
pub fn try_latest(year: i16, month: i8, number: &'a str) -> ArticleIdResult<'a>
This allows manually creating an ArticleId from the given components without a version
(assuming it is the latest version), and will also validate each component for correctness.
If any component is invalid, it will return an ArticleIdError.
§Examples
use arxiv::ArticleId;
let id = ArticleId::try_latest(2011, 1, "00001");
assert!(id.is_ok());Sourcepub const fn is_latest(&self) -> bool
pub const fn is_latest(&self) -> bool
Whether or not the identifier refers to the most recent version of the arXiv article
Sourcepub const fn year(&self) -> i16
pub const fn year(&self) -> i16
The year the arXiv publication was published in
§Examples
use arxiv::ArticleId;
let id = ArticleId::try_from("arXiv:2304.11188v1").unwrap();
assert_eq!(id.year(), 2023);Sourcepub const fn month(&self) -> i8
pub const fn month(&self) -> i8
The month the arXiv publication was published in
§Examples
use arxiv::ArticleId;
let id = ArticleId::try_from("arXiv:2304.11188v1").unwrap();
assert_eq!(id.month(), 04);Sourcepub fn number(&self) -> &'a str
pub fn number(&self) -> &'a str
The uniquely assigned identifier of the arXiv publication
§Examples
use arxiv::ArticleId;
let id = ArticleId::try_from("arXiv:2304.11188v1").unwrap();
assert_eq!(id.number(), "11188");Sourcepub const fn version(&self) -> ArticleVersion
pub const fn version(&self) -> ArticleVersion
The latest version of the arXiv publication, if any.
§Examples
use arxiv::{ArticleId, ArticleVersion};
let id = ArticleId::try_from("arXiv:2304.11188v1").unwrap();
assert_eq!(id.version(), ArticleVersion::Num(1));Sourcepub fn set_version(&mut self, version: u8)
pub fn set_version(&mut self, version: u8)
Sets the version of the arXiv article.
§Examples
use arxiv::{ArticleId, ArticleVersion};
let mut id = ArticleId::try_from("arXiv:2001.00001").unwrap();
assert_eq!(id.version(), ArticleVersion::Latest);
id.set_version(1);
assert_eq!(id.version(), ArticleVersion::Num(1));Sourcepub fn set_latest(&mut self)
pub fn set_latest(&mut self)
Sets the version of the arXiv article to the latest version.
§Examples
use arxiv::{ArticleId, ArticleVersion};
let mut id = ArticleId::try_from("arXiv:2001.00001v1").unwrap();
assert_eq!(id.version(), ArticleVersion::Num(1));
id.set_latest();
assert_eq!(id.version(), ArticleVersion::Latest);Sourcepub fn as_unique_ident(&self) -> String
pub fn as_unique_ident(&self) -> String
Display the id as a unique identifier (after the arXiv literal)
use arxiv::{ArticleId};
let id = ArticleId::new_versioned(2020, 10, "14462", 2);
assert_eq!(id.as_unique_ident(), "2010.14462");Sourcepub fn as_url(&self) -> Url
Available on crate feature url only.
pub fn as_url(&self) -> Url
url only.Converts the article identifier to a URL where the abstract page is.
use arxiv::ArticleId;
use url::Url;
let id = ArticleId::new_versioned(2020, 10, "14462", 2);
let url = Url::from(id);
assert_eq!(url.to_string(), "https://arxiv.org/abs/2010.14462v2");