pub struct Client {
pub pubmed: PubMedClient,
pub pmc: PmcClient,
}Expand description
Convenience client that combines both PubMed and PMC functionality
Fields§
§pubmed: PubMedClientPubMed client for metadata
pmc: PmcClientPMC client for full text
Implementations§
Source§impl Client
impl Client
Sourcepub fn new() -> Self
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_rs::Client;
let client = Client::new();Sourcepub fn with_config(config: ClientConfig) -> Self
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_rs::{Client, ClientConfig};
let config = ClientConfig::new()
.with_api_key("your_api_key_here")
.with_email("researcher@university.edu");
let client = Client::with_config(config);Sourcepub fn with_http_client(http_client: Client) -> Self
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_rs::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);Sourcepub async fn search_with_full_text(
&self,
query: &str,
limit: usize,
) -> Result<Vec<(PubMedArticle, Option<PmcFullText>)>>
pub async fn search_with_full_text( &self, query: &str, limit: usize, ) -> Result<Vec<(PubMedArticle, Option<PmcFullText>)>>
Search for articles and attempt to fetch full text for each
§Arguments
query- Search query stringlimit- Maximum number of articles to process
§Returns
Returns a vector of tuples containing (PubMedArticle, Option<PmcFullText>)
§Example
use pubmed_client_rs::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(())
}Sourcepub async fn fetch_articles(&self, pmids: &[&str]) -> Result<Vec<PubMedArticle>>
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_rs::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(())
}Sourcepub async fn fetch_summaries(
&self,
pmids: &[&str],
) -> Result<Vec<ArticleSummary>>
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_rs::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(())
}Sourcepub async fn search_and_fetch_summaries(
&self,
query: &str,
limit: usize,
) -> Result<Vec<ArticleSummary>>
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 stringlimit- Maximum number of articles
§Returns
Returns a Result<Vec<ArticleSummary>> containing lightweight article metadata
§Example
use pubmed_client_rs::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(())
}Sourcepub async fn get_database_list(&self) -> Result<Vec<String>>
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_rs::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(())
}Sourcepub async fn get_database_info(&self, database: &str) -> Result<DatabaseInfo>
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_rs::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_rs::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(())
}Sourcepub async fn get_pmc_links(&self, pmids: &[u32]) -> Result<PmcLinks>
pub async fn get_pmc_links(&self, pmids: &[u32]) -> Result<PmcLinks>
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_rs::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(())
}Sourcepub async fn get_citations(&self, pmids: &[u32]) -> Result<Citations>
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_rs::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(())
}Sourcepub async fn match_citations(
&self,
citations: &[CitationQuery],
) -> Result<CitationMatches>
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_rs::{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(())
}Sourcepub async fn global_query(&self, term: &str) -> Result<GlobalQueryResults>
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_rs::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(())
}Sourcepub async fn spell_check(&self, term: &str) -> Result<SpellCheckResult>
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_rs::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§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnsafeUnpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().