ArticleId

Struct ArticleId 

Source
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>

Source

pub const MIN_YEAR: i16 = 2_007i16

Source

pub const MAX_YEAR: i16 = 2_099i16

Source

pub const MIN_NUM_DIGITS: usize = 4usize

Source

pub const MAX_NUM_DIGITS: usize = 5usize

Source

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));
Source

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");
Source

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));
Source

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());
Source

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());
Source

pub const fn is_latest(&self) -> bool

Whether or not the identifier refers to the most recent version of the arXiv article

Source

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);
Source

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);
Source

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");
Source

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));
Source

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));
Source

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);
Source

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");
Source

pub fn as_url(&self) -> Url

Available on crate feature 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");

Trait Implementations§

Source§

impl<'a> Clone for ArticleId<'a>

Source§

fn clone(&self) -> ArticleId<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for ArticleId<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ArticleId<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult

Formats the value using the given formatter. Read more
Source§

impl<'a> From<ArticleId<'a>> for Url

Available on crate feature url only.
Source§

fn from(id: ArticleId<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> Hash for ArticleId<'a>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> Ord for ArticleId<'a>

Source§

fn cmp(&self, other: &ArticleId<'a>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<'a> PartialEq for ArticleId<'a>

Source§

fn eq(&self, other: &ArticleId<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialOrd for ArticleId<'a>

Source§

fn partial_cmp(&self, other: &ArticleId<'a>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a> TryFrom<&'a str> for ArticleId<'a>

Source§

type Error = ArticleIdError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &'a str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> Copy for ArticleId<'a>

Source§

impl<'a> Eq for ArticleId<'a>

Source§

impl<'a> StructuralPartialEq for ArticleId<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for ArticleId<'a>

§

impl<'a> RefUnwindSafe for ArticleId<'a>

§

impl<'a> Send for ArticleId<'a>

§

impl<'a> Sync for ArticleId<'a>

§

impl<'a> Unpin for ArticleId<'a>

§

impl<'a> UnwindSafe for ArticleId<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,