Skip to main content

Crossref

Struct Crossref 

Source
pub struct Crossref {
    pub base_url: String,
    pub http_client: Client,
}
Expand description

Struct for Crossref search API methods

Fields§

§base_url: String

use another base url than api.crossref.org

§http_client: Client

the reqwest client that handles the requests

Implementations§

Source§

impl Crossref

Source

pub fn builder() -> CrossrefBuilder

Constructs a new CrossrefBuilder.

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

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::query_works]

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

let query = WorksQuery::new("Machine Learning")
    .filter(WorksFilter::HasOrcid)
    .order(crossref::Order::Asc)
    .field_query(FieldQuery::author("Some Author"))
    .sort(crossref::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 async fn deep_page<T: Into<WorkListQuery>>(&self, query: T) -> Vec<WorkList>

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::{Crossref, WorksQuery, Work};
let client = Crossref::builder().build()?;

let all_works: Vec<Work> = client.deep_page(WorksQuery::new("Machine Learning")).await.into_iter().flat_map(|x|x.items).collect();
§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::{Crossref, Funders, WorksQuery, Work, WorkList};
let client = Crossref::builder().build()?;

let all_funder_work_list: Vec<WorkList> = client.deep_page(WorksQuery::default().into_combined_query::<Funders>("funder id")).await;
§Example

Iterate over all Work items of a specific funder directly.

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

let all_works: Vec<Work> = client.deep_page(WorksQuery::default()
        .into_combined_query::<Funders>("funder id"))
        .await
        .into_iter()
        .flat_map(|x| x.items)
        .collect();
§Example

Alternatively deep page without an iterator by handling the cursor directly

ⓘ
use crossref::{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 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 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::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) -> Crossref

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