Skip to main content

Crossref

Struct Crossref 

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

Struct for Crossref search API methods

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

Implementations§

Source§

impl Crossref

Source

pub fn builder() -> CrossrefBuilder

Constructs a new CrossrefBuilder.

This is the same as Crossref::builder().

Source

pub fn base_url(&self) -> &str

The url every route is appended to, https://api.crossref.org unless CrossrefBuilder::base_url said otherwise.

Source

pub fn rate_limit(&self) -> RateLimit

The request budget crossref last reported for this client.

Crossref sends the budget on every response and the client paces itself against it, so before the first request this is the assumed RateLimit::CONSERVATIVE (or whatever CrossrefBuilder::rate_limit was given) and afterwards it is what crossref actually granted.

Source

pub fn api_pool(&self) -> Option<String>

The pool crossref sorted the last request into, from x-api-pool.

polite if CrossrefBuilder::polite worked, plus for a Plus token, otherwise public. None before the first request.

Source

pub async fn funder_works(&self, ident: WorksIdentQuery) -> Result<WorkList>

Return one page of the components’s Work that match the query

Source

pub async fn member_works(&self, ident: WorksIdentQuery) -> Result<WorkList>

Return one page of the components’s Work that match the query

Source

pub async fn type_works(&self, ident: WorksIdentQuery) -> Result<WorkList>

Return one page of the components’s Work that match the query

Source

pub async fn journal_works(&self, ident: WorksIdentQuery) -> Result<WorkList>

Return one page of the components’s Work that match the query

Source

pub async fn prefix_works(&self, ident: WorksIdentQuery) -> Result<WorkList>

Return one page of the components’s Work that match the query

Source

pub async fn works<T: Into<WorkListQuery>>(&self, query: T) -> Result<WorkList>

Return the Work items that match a certain query.

To search only by query terms use the convenience query method Crossref::works

§Example
use crossref_client::{Crossref, WorksQuery, WorksFilter, FieldQuery};
let client = Crossref::builder().build()?;

let query = WorksQuery::new("Machine Learning")
    .filter(WorksFilter::HasOrcid)
    .order(crossref_client::Order::Asc)
    .field_query(FieldQuery::author("Some Author"))
    .sort(crossref_client::Sort::Score);

let works = client.works(query).await?;
§Errors

This method fails if the works element expands to a bad route ResourceNotFound Fails if the response body doesn’t have message field MissingMessage. Fails if anything else than a WorkList is returned as message UnexpectedItem

Source

pub async fn work(&self, doi: &str) -> Result<Work>

Return the Work that is identified by the doi.

§Errors

This method fails if the doi could not identified ResourceNotFound

Source

pub fn deep_page<T: Into<WorkListQuery>>( &self, query: T, ) -> WorkListIterator<'_>

Deep paging results Deep paging is supported for all queries, that return a list of Work, WorkList. This function returns a new iterator over pages of Work, which is returned as bulk of items as a WorkList by crossref. Usually a single page WorkList contains 20 items.

§Example

Iterate over all Works linked to search term Machine Learning

use crossref_client::{AsyncIterator, Crossref, WorksQuery, Work};
let client = Crossref::builder().build()?;

let mut pages = client.deep_page(WorksQuery::new("Machine Learning"));
let mut all_works: Vec<Work> = Vec::new();
while let Some(page) = pages.next().await {
    let page = page?;
    all_works.extend(page.items);
}
§Example

Iterate over all the pages (WorkList) of the funder with id funder id by using a combined query. A single WorkList usually holds 20 Work items.

use crossref_client::{AsyncIterator, Crossref, Funders, WorksQuery, Work, WorkList};
let client = Crossref::builder().build()?;

let mut pages = client.deep_page(WorksQuery::default().into_combined_query::<Funders>("funder id"));
let mut all_funder_work_list: Vec<WorkList> = Vec::new();
while let Some(page) = pages.next().await {
    let page = page?;
    all_funder_work_list.push(page);
}
§Example

Iterate over all Work items of a specfic funder directly.

use crossref_client::{AsyncIterator, Crossref, Funders, WorksQuery, Work, WorkList};
let client = Crossref::builder().build()?;

let mut works = client.deep_page(WorksQuery::default()
        .into_combined_query::<Funders>("funder id"))
        .into_work_iter();
let mut all_works: Vec<Work> = Vec::new();
while let Some(work) = works.next().await {
    let work = work?;
    all_works.push(work);
}
§Example

Alternatively deep page without an iterator by handling the cursor directly

use crossref_client::{Crossref, WorksQuery, WorksFilter};
let client = Crossref::builder().build()?;

// request a next-cursor first
let query = WorksQuery::new("Machine Learning")
    .new_cursor();

let works = client.works(query.clone()).await?;

// this continues from where this first response stopped
// if no more work items are available then a empty list will be returned
let deep_works = client.works(
    query.next_cursor(&works.next_cursor.unwrap())
).await?;
Source

pub async fn transform(&self, doi: &str, format: &CnFormat) -> Result<String>

Re-serialize the work identified by doi into another format.

Crossref renders the registered metadata itself, so this never goes through Work and the body is returned verbatim – BibTeX, RIS, RDF or a citation formatted in a CSL style.

§Example
use crossref_client::{CnFormat, Crossref};
let bibtex = client
    .transform("10.1037/0003-066X.59.1.29", &CnFormat::BibTex)
    .await?;

let citation = client
    .transform("10.1037/0003-066X.59.1.29", &CnFormat::bibliography("apa"))
    .await?;
§Errors

Fails with Error::ValidationFailure if crossref cannot serve the format for this DOI – an unknown CSL style is the usual cause.

Source

pub async fn styles(&self) -> Result<StyleList>

Return the CSL styles crossref can render a citation in, for CnFormat::Bibliography.

Roughly 2 900 of them, in one response.

Source

pub async fn work_agency(&self, doi: &str) -> Result<WorkAgency>

Return the Agency that registers the Work identified by the doi.

§Errors

This method fails if the doi could not identified ResourceNotFound

Source

pub async fn funders(&self, funders: FundersQuery) -> Result<FunderList>

Return the matching Funders items.

Source

pub async fn funder(&self, id: &str) -> Result<Funder>

Return the Funder for the id

Source

pub async fn members(&self, members: MembersQuery) -> Result<MemberList>

Return the matching Members items.

Source

pub async fn member(&self, member_id: &str) -> Result<Member>

Return the Member for the id

Source

pub async fn prefix(&self, id: &str) -> Result<Prefix>

Return the Prefix for the id

Source

pub async fn journal(&self, id: &str) -> Result<Journal>

Return a specific Journal

Source

pub async fn journals(&self, journals: JournalsQuery) -> Result<JournalList>

Return the matching Journal items.

§Example
use crossref_client::{Crossref, JournalsQuery, ResultControl};
let journals = client
    .journals(JournalsQuery::new("Economic Geography").result_control(ResultControl::Rows(10)))
    .await?;
Source

pub async fn licenses(&self, licenses: LicensesQuery) -> Result<LicenseList>

Return the licenses works in the crossref metadata are published under, each with the number of works that carry it.

§Example
use crossref_client::{Crossref, LicensesQuery, ResultControl};
let licenses = client
    .licenses(LicensesQuery::new("creative commons").result_control(ResultControl::Rows(10)))
    .await?;

for license in &licenses.items {
    println!("{:>8} {}", license.work_count, license.url);
}
Source

pub async fn types(&self) -> Result<TypeList>

Return all available Type

Source

pub async fn type_(&self, id: &Type) -> Result<CrossrefType>

Return the Type for the id

Source

pub async fn random_dois(&self, len: usize) -> Result<Vec<String>>

Get a random set of DOIs

§Example
use crossref_client::Crossref;
// this will return 10 random dois from the crossref api
let random_dois = client.random_dois(10).await?;

Trait Implementations§

Source§

impl Clone for Crossref

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 Crossref

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