Client

Struct Client 

Source
pub struct Client {
    pub pubmed: PubMedClient,
    pub pmc: PmcClient,
}
Expand description

Convenience client that combines both PubMed and PMC functionality

Fields§

§pubmed: PubMedClient

PubMed client for metadata

§pmc: PmcClient

PMC client for full text

Implementations§

Source§

impl Client

Source

pub fn new() -> Self

Create a new combined client with default configuration

Uses default NCBI rate limiting (3 requests/second) and no API key. For production use, consider using with_config() to set an API key.

§Example
use pubmed_client::Client;

let client = Client::new();
Source

pub fn with_config(config: ClientConfig) -> Self

Create a new combined client with custom configuration

Both PubMed and PMC clients will use the same configuration for consistent rate limiting and API key usage.

§Arguments
  • config - Client configuration including rate limits, API key, etc.
§Example
use pubmed_client::{Client, ClientConfig};

let config = ClientConfig::new()
    .with_api_key("your_api_key_here")
    .with_email("researcher@university.edu");

let client = Client::with_config(config);
Source

pub fn with_http_client(http_client: Client) -> Self

Create a new combined client with custom HTTP client

§Arguments
  • http_client - Custom reqwest client with specific configuration
§Example
use pubmed_client::Client;
use reqwest::ClientBuilder;
use std::time::Duration;

let http_client = ClientBuilder::new()
    .timeout(Duration::from_secs(30))
    .build()
    .unwrap();

let client = Client::with_http_client(http_client);
Source

pub async fn search_with_full_text( &self, query: &str, limit: usize, ) -> Result<Vec<(PubMedArticle, Option<PmcArticle>)>>

Search for articles and attempt to fetch full text for each

§Arguments
  • query - Search query string
  • limit - Maximum number of articles to process
§Returns

Returns a vector of tuples containing (PubMedArticle, Option<PmcArticle>)

§Example
use pubmed_client::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let results = client.search_with_full_text("covid-19", 5).await?;

    for (article, full_text) in results {
        println!("Article: {}", article.title);
        if let Some(ft) = full_text {
            println!("  Full text available with {} sections", ft.sections.len());
        } else {
            println!("  Full text not available");
        }
    }

    Ok(())
}
Source

pub async fn fetch_articles(&self, pmids: &[&str]) -> Result<Vec<PubMedArticle>>

Fetch multiple articles by PMIDs in a single batch request

This is significantly more efficient than fetching articles one by one, as it sends fewer HTTP requests to the NCBI API.

§Arguments
  • pmids - Slice of PubMed IDs as strings
§Returns

Returns a Result<Vec<PubMedArticle>> containing articles with metadata

§Example
use pubmed_client::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let articles = client.fetch_articles(&["31978945", "33515491"]).await?;
    for article in &articles {
        println!("{}: {}", article.pmid, article.title);
    }
    Ok(())
}
Source

pub async fn fetch_summaries( &self, pmids: &[&str], ) -> Result<Vec<ArticleSummary>>

Fetch lightweight article summaries by PMIDs using the ESummary API

Returns basic metadata (title, authors, journal, dates, DOI) without abstracts, MeSH terms, or chemical lists. Faster than fetch_articles() when you only need bibliographic overview data.

§Arguments
  • pmids - Slice of PubMed IDs as strings
§Returns

Returns a Result<Vec<ArticleSummary>> containing lightweight article metadata

§Example
use pubmed_client::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let summaries = client.fetch_summaries(&["31978945", "33515491"]).await?;
    for summary in &summaries {
        println!("{}: {}", summary.pmid, summary.title);
    }
    Ok(())
}
Source

pub async fn search_and_fetch_summaries( &self, query: &str, limit: usize, ) -> Result<Vec<ArticleSummary>>

Search and fetch lightweight summaries in a single operation

Combines search and ESummary fetch. Use this when you only need basic metadata (title, authors, journal, dates) and want faster retrieval than search_and_fetch() which uses EFetch.

§Arguments
  • query - Search query string
  • limit - Maximum number of articles
§Returns

Returns a Result<Vec<ArticleSummary>> containing lightweight article metadata

§Example
use pubmed_client::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let summaries = client.search_and_fetch_summaries("covid-19", 20).await?;
    for summary in &summaries {
        println!("{}: {}", summary.pmid, summary.title);
    }
    Ok(())
}
Source

pub async fn get_database_list(&self) -> Result<Vec<String>>

Get list of all available NCBI databases

§Returns

Returns a Result<Vec<String>> containing names of all available databases

§Example
use pubmed_client::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let databases = client.get_database_list().await?;
    println!("Available databases: {:?}", databases);
    Ok(())
}
Source

pub async fn get_database_info(&self, database: &str) -> Result<DatabaseInfo>

Get detailed information about a specific database

§Arguments
  • database - Name of the database (e.g., “pubmed”, “pmc”, “books”)
§Returns

Returns a Result<DatabaseInfo> containing detailed database information

§Example
use pubmed_client::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let db_info = client.get_database_info("pubmed").await?;
    println!("Database: {}", db_info.name);
    println!("Description: {}", db_info.description);
    println!("Fields: {}", db_info.fields.len());
    Ok(())
}

Get related articles for given PMIDs

§Arguments
  • pmids - List of PubMed IDs to find related articles for
§Returns

Returns a Result<RelatedArticles> containing related article information

§Example
use pubmed_client::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let related = client.get_related_articles(&[31978945]).await?;
    println!("Found {} related articles", related.related_pmids.len());
    Ok(())
}

Get PMC links for given PMIDs (full-text availability)

§Arguments
  • pmids - List of PubMed IDs to check for PMC availability
§Returns

Returns a Result<PmcLinks> containing PMC IDs with full text available

§Example
use pubmed_client::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let pmc_links = client.get_pmc_links(&[31978945]).await?;
    println!("Found {} PMC articles", pmc_links.pmc_ids.len());
    Ok(())
}
Source

pub async fn get_citations(&self, pmids: &[u32]) -> Result<Citations>

Get citing articles for given PMIDs

§Arguments
  • pmids - List of PubMed IDs to find citing articles for
§Returns

Returns a Result<Citations> containing citing article information

§Example
use pubmed_client::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let citations = client.get_citations(&[31978945]).await?;
    println!("Found {} citing articles", citations.citing_pmids.len());
    Ok(())
}
Source

pub async fn match_citations( &self, citations: &[CitationQuery], ) -> Result<CitationMatches>

Match citations to PMIDs using the ECitMatch API

§Arguments
  • citations - List of citation queries to match
§Returns

Returns a Result<CitationMatches> containing match results

§Example
use pubmed_client::{Client, CitationQuery};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let citations = vec![
        CitationQuery::new("science", "1987", "235", "182", "palmenberg ac", "ref1"),
    ];
    let results = client.match_citations(&citations).await?;
    println!("Found {} matches", results.found_count());
    Ok(())
}
Source

pub async fn global_query(&self, term: &str) -> Result<GlobalQueryResults>

Query all NCBI databases for record counts

§Arguments
  • term - Search query string
§Returns

Returns a Result<GlobalQueryResults> containing counts per database

§Example
use pubmed_client::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let results = client.global_query("asthma").await?;
    for db in results.non_zero() {
        println!("{}: {} records", db.menu_name, db.count);
    }
    Ok(())
}
Source

pub async fn epost(&self, pmids: &[&str]) -> Result<EPostResult>

Upload a list of PMIDs to the NCBI History server using EPost

§Arguments
  • pmids - Slice of PubMed IDs as strings
§Returns

Returns a Result<EPostResult> containing WebEnv and query_key

§Example
use pubmed_client::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let result = client.epost(&["31978945", "33515491"]).await?;
    let session = result.history_session();
    let articles = client.pubmed.fetch_from_history(&session, 0, 100).await?;
    println!("Fetched {} articles", articles.len());
    Ok(())
}
Source

pub async fn fetch_all_by_pmids( &self, pmids: &[&str], ) -> Result<Vec<PubMedArticle>>

Fetch all articles for a list of PMIDs using EPost and the History server

Uploads the PMID list via EPost (HTTP POST), then fetches articles in paginated batches. Recommended for large PMID lists (hundreds or thousands).

§Example
use pubmed_client::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let articles = client.fetch_all_by_pmids(&["31978945", "33515491"]).await?;
    for a in &articles {
        println!("{}: {}", a.pmid, a.title);
    }
    Ok(())
}
Source

pub async fn spell_check(&self, term: &str) -> Result<SpellCheckResult>

Check spelling of a search term using the ESpell API

Provides spelling suggestions for terms within a single text query. Uses the PubMed database by default. For other databases, use client.pubmed.spell_check_db(term, db) directly.

§Arguments
  • term - The search term to spell-check
§Returns

Returns a Result<SpellCheckResult> containing spelling suggestions

§Example
use pubmed_client::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    let result = client.spell_check("asthmaa").await?;
    println!("Corrected: {}", result.corrected_query);
    Ok(())
}

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

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 Default for Client

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

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.

§

impl<T> Instrument for T

§

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

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

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: 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<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
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 = 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

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