pub struct PmcCloudClient { /* private fields */ }Expand description
Download client for PMC Open Access articles via the PMC OA Cloud (AWS S3).
Fetches an article’s full-text XML, media, and supplementary files as
individual per-article objects from the pmc-oa-opendata S3 bucket. This
replaces the retired PMC FTP service and its legacy oa_package tar.gz
bundles (removed by NCBI in August 2026).
Implementations§
Source§impl PmcCloudClient
impl PmcCloudClient
Sourcepub fn new(config: ClientConfig) -> Self
pub fn new(config: ClientConfig) -> Self
Create a new PMC OA Cloud client with configuration
Sourcepub async fn download_files<P: AsRef<Path>>(
&self,
pmcid: &str,
output_dir: P,
) -> Result<Vec<String>>
pub async fn download_files<P: AsRef<Path>>( &self, pmcid: &str, output_dir: P, ) -> Result<Vec<String>>
Download a PMC article’s files from the PMC OA Cloud (AWS S3) service.
NCBI retired the PMC FTP service and the legacy oa_package tar.gz
bundles (August 2026). This downloads each of the article’s files
(full-text XML, media, supplementary materials, PDF, etc.) individually
from the pmc-oa-opendata S3 bucket into output_dir.
§Arguments
pmcid- PMC ID (with or without “PMC” prefix)output_dir- Directory to download the article’s files into
§Returns
Returns a Result<Vec<String>> containing the list of downloaded file paths
§Errors
ParseError::InvalidPmid- If the PMCID format is invalidPubMedError::RequestError- If the HTTP request failsParseError::IoError- If file operations failParseError::PmcNotAvailable- If the article is not available in the OA Cloud
§Example
use pubmed_client::pmc::cloud::PmcCloudClient;
use pubmed_client::ClientConfig;
use std::path::Path;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = ClientConfig::new();
let client = PmcCloudClient::new(config);
let output_dir = Path::new("./extracted_articles");
let files = client.download_files("PMC7906746", output_dir).await?;
for file in files {
println!("Downloaded: {}", file);
}
Ok(())
}Sourcepub async fn extract_figures_with_captions<P: AsRef<Path>>(
&self,
pmcid: &str,
output_dir: P,
) -> Result<Vec<ExtractedFigure>>
pub async fn extract_figures_with_captions<P: AsRef<Path>>( &self, pmcid: &str, output_dir: P, ) -> Result<Vec<ExtractedFigure>>
Download the article’s files and match figures with their captions from XML
§Arguments
pmcid- PMC ID (with or without “PMC” prefix)output_dir- Directory to download the article’s files into
§Returns
Returns a Result<Vec<ExtractedFigure>> containing figures with both XML metadata and file paths
§Errors
ParseError::InvalidPmid- If the PMCID format is invalidPubMedError::RequestError- If the HTTP request failsParseError::IoError- If file operations failParseError::PmcNotAvailable- If the article is not available in OA
§Example
use pubmed_client::pmc::cloud::PmcCloudClient;
use pubmed_client::ClientConfig;
use std::path::Path;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = ClientConfig::new();
let client = PmcCloudClient::new(config);
let output_dir = Path::new("./extracted_articles");
let figures = client.extract_figures_with_captions("PMC7906746", output_dir).await?;
for figure in figures {
println!("Figure {}: {:?}", figure.figure.id, figure.figure.caption);
println!("File: {}", figure.extracted_file_path);
}
Ok(())
}Sourcepub fn find_matching_file(
figure: &Figure,
extracted_files: &[String],
image_extensions: &[&str],
) -> Option<String>
pub fn find_matching_file( figure: &Figure, extracted_files: &[String], image_extensions: &[&str], ) -> Option<String>
Find a matching file for a figure based on ID, label, or filename patterns.
Three rules are tried in order, returning the first extracted file that matches:
- the explicit
graphic_href(case-sensitive substring of the file name, any extension); - the figure
id(case-insensitive substring) with an image extension; - the figure
labelwith whitespace/dots stripped (case-insensitive) with an image extension.
Trait Implementations§
Source§impl Clone for PmcCloudClient
impl Clone for PmcCloudClient
Source§fn clone(&self) -> PmcCloudClient
fn clone(&self) -> PmcCloudClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more