Skip to main content

OpenCitations

Struct OpenCitations 

Source
pub struct OpenCitations { /* private fields */ }
Expand description

An async client for the OpenCitations Index and Meta apis.

Cloning is cheap and shares the connection pool and the rate limiter, so concurrent callers should clone one client rather than build several.

Implementations§

Source§

impl OpenCitations

Source

pub const META_BATCH: usize = 10

How many identifiers Self::metadata puts in one request.

Meta answers a 500 at fifteen identifiers and succeeds at fourteen, whichever ids they are — a cap it does not document and does not mention in the error. Ten leaves room for that edge to move without this crate finding out from a user.

Source

pub fn builder() -> OpenCitationsBuilder

Constructs a new OpenCitationsBuilder.

Source

pub fn base_url(&self) -> &str

The url every route is appended to, https://api.opencitations.net unless OpenCitationsBuilder::base_url said otherwise.

Source

pub fn rate_limit(&self) -> RateLimit

The rate this client is pacing itself at.

OpenCitations reports no budget of its own, so this is whatever the builder was given and never changes.

Source

pub async fn citations(&self, id: &Identifier) -> Result<Vec<Citation>>

The works that cite id — the direction crossref cannot answer.

Empty when nothing cites it and when OpenCitations has never indexed it; the two are not distinguishable. Unpaged, so a heavily cited work arrives in one large response — narrow it with OpenCitations::citations_where rather than here.

Source

pub async fn citations_where( &self, id: &Identifier, refine: &Refine, ) -> Result<Vec<Citation>>

The works that cite id, narrowed and ordered by the api.

use opencitations_client::{Field, Filter, Identifier, OpenCitations, Refine, Sort};

let recent = Refine::new()
    .filter(Filter::greater_than(Field::Creation, "2023"))
    .sort(Sort::descending(Field::Creation));

let citations = client
    .citations_where(&Identifier::doi("10.1016/j.marpol.2021.104855"), &recent)
    .await?;
Source

pub async fn references(&self, id: &Identifier) -> Result<Vec<Citation>>

The works id cites, as OpenCitations indexed them.

This is the same direction as crossref’s reference[] and a useful cross-check on it: OpenCitations resolves references to identifiers, where a crossref reference may be an unstructured string.

Source

pub async fn references_where( &self, id: &Identifier, refine: &Refine, ) -> Result<Vec<Citation>>

The works id cites, narrowed and ordered by the api.

Source

pub async fn citation(&self, oci: &Oci) -> Result<Option<Citation>>

One citation, by its own identifier.

None when OpenCitations holds no such citation.

Source

pub async fn citation_count(&self, id: &Identifier) -> Result<u64>

How many works cite id.

Cheaper than counting OpenCitations::citations, which fetches every edge to do it.

Source

pub async fn reference_count(&self, id: &Identifier) -> Result<u64>

How many works id cites.

Source

pub async fn venue_citation_count(&self, issn: &Identifier) -> Result<u64>

How many citations everything published in a venue has received.

Addressed by ISSN — Identifier::issn("0308-597X").

Source

pub async fn metadata(&self, ids: &[Identifier]) -> Result<Vec<Metadata>>

The bibliographic records behind any number of identifiers.

Ids are batched rather than asked about one at a time, which is worth doing: a batch is one slot of the rate limit rather than one each. More than Self::META_BATCH of them is split across several requests, paced like any other.

Records come back in whatever order Meta answers in, and an id it holds nothing about is simply absent — so match the results up by Metadata::id rather than by position. An empty slice makes no request.

let records = client
    .metadata(&[
        Identifier::doi("10.1016/j.marpol.2021.104855"),
        Identifier::doi("10.1038/nature12373"),
    ])
    .await?;

Trait Implementations§

Source§

impl Clone for OpenCitations

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for OpenCitations

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more