pub struct Pdg { /* private fields */ }Expand description
Handle for querying the Particle Data Group database.
Create a handle with Pdg::open, then use lookup methods such as
Pdg::particle, Pdg::mcid, Pdg::search_particles, and
Pdg::search_text to retrieve typed records.
§Examples
use pdg_rs::Pdg;
let pdg = Pdg::open()?;
let pion = pdg.particle("pi+")?.expect("pi+ is in the PDG database");
assert_eq!(pion.name, "pi+");Implementations§
Source§impl Pdg
impl Pdg
Sourcepub fn open() -> PdgResult<Self>
pub fn open() -> PdgResult<Self>
Opens the default PDG SQLite database.
If PDG_RS_DB_PATH is set, that exact database file is opened. Otherwise,
the default database is loaded from the local cache, downloading and
verifying it first when needed.
This also initializes the temporary full-text search index used by
Pdg::search_text.
§Errors
Returns an error if the configured database cannot be opened, the cached database cannot be verified, or the default database cannot be downloaded.
Sourcepub fn open_cached() -> PdgResult<Self>
pub fn open_cached() -> PdgResult<Self>
Opens the default PDG SQLite database without downloading it.
If PDG_RS_DB_PATH is set, that exact database file is opened. Otherwise,
this opens the verified cached copy of the default database.
§Errors
Returns PdgError::OfflineDatabaseMissing if the default database is
not cached. Returns another error if the configured database cannot be
opened or the cached database cannot be verified.
Sourcepub fn ensure_database() -> PdgResult<PathBuf>
pub fn ensure_database() -> PdgResult<PathBuf>
Ensures the default database exists in the local cache and returns its path.
If PDG_RS_DB_PATH is set, this returns that path without downloading or
validating it. Otherwise, this downloads the default database when it is
missing or invalid, unless PDG_RS_OFFLINE disables network access.
§Errors
Returns an error if the cache directory is unavailable, the database cannot be downloaded, or the downloaded file fails verification.
Sourcepub fn cached_database_path() -> PdgResult<PathBuf>
pub fn cached_database_path() -> PdgResult<PathBuf>
Returns the cache path for the default database.
This does not check whether the database exists and does not consider
PDG_RS_DB_PATH, which is an explicit override rather than a cache path.
§Errors
Returns PdgError::CacheDirectoryUnavailable if no cache directory can
be found.
Sourcepub const fn db(&self) -> &Connection
pub const fn db(&self) -> &Connection
Returns the underlying SQLite connection.
This is useful for advanced queries that are not covered by the typed
API. Prefer the typed methods where possible because they preserve links
back to this Pdg handle.
Sourcepub fn particle(
&self,
name: impl Into<String>,
) -> PdgResult<Option<PdgParticle<'_>>>
pub fn particle( &self, name: impl Into<String>, ) -> PdgResult<Option<PdgParticle<'_>>>
Looks up a particle by its PDG item name.
Use Pdg::particle_by_pdgid when you already have a PDG identifier,
or Pdg::mcid when you have a Monte Carlo particle ID.
§Errors
Returns a database error if the query cannot be executed.
Sourcepub fn particle_by_pdgid(
&self,
pdgid: impl Into<String>,
) -> PdgResult<Option<PdgParticle<'_>>>
pub fn particle_by_pdgid( &self, pdgid: impl Into<String>, ) -> PdgResult<Option<PdgParticle<'_>>>
Looks up a particle by PDG identifier, case-insensitively.
§Errors
Returns a database error if the query cannot be executed.
Sourcepub fn pdgid(&self, pdgid: impl Into<String>) -> PdgResult<Option<PdgIdEntry>>
pub fn pdgid(&self, pdgid: impl Into<String>) -> PdgResult<Option<PdgIdEntry>>
Looks up raw metadata for a PDG identifier.
This returns a PdgIdEntry for any PDG row type, not just particle
rows.
§Errors
Returns a database error if the query cannot be executed.
Sourcepub fn search_text(
&self,
query: impl Into<String>,
) -> PdgResult<Vec<TextSearchResult>>
pub fn search_text( &self, query: impl Into<String>, ) -> PdgResult<Vec<TextSearchResult>>
Searches descriptions, text blocks, and footnotes with SQLite FTS5.
Non-alphanumeric separators are normalized into individual quoted search terms before querying the index.
§Examples
use pdg_rs::{Pdg, TextSearchSource};
let pdg = Pdg::open()?;
let results = pdg.search_text("K(S)0 mean life")?;
assert!(results.iter().any(|result| {
result.source == TextSearchSource::Description
}));§Errors
Returns a database error if the search query cannot be executed.
Sourcepub fn mcid(&self, mcid: isize) -> PdgResult<Option<PdgParticle<'_>>>
pub fn mcid(&self, mcid: isize) -> PdgResult<Option<PdgParticle<'_>>>
Looks up a particle by its Monte Carlo particle ID.
§Errors
Returns a database error if the query cannot be executed.
Sourcepub fn search_particles(
&self,
query: ParticleSearchQuery,
) -> PdgResult<Vec<PdgParticle<'_>>>
pub fn search_particles( &self, query: ParticleSearchQuery, ) -> PdgResult<Vec<PdgParticle<'_>>>
Searches particles using a ParticleSearchQuery.
§Examples
use pdg_rs::{Charge, ParticleClass, ParticleSearchQuery, Pdg};
let pdg = Pdg::open()?;
let charged_mesons = pdg.search_particles(
ParticleSearchQuery::new()
.class(ParticleClass::Meson)
.charge(Charge::Plus),
)?;
assert!(charged_mesons.iter().any(|particle| particle.name == "pi+"));§Errors
Returns a database error if any particle, property, or decay filter query cannot be executed.
Sourcepub fn item(&self, name: impl Into<String>) -> PdgResult<Option<PdgItem<'_>>>
pub fn item(&self, name: impl Into<String>) -> PdgResult<Option<PdgItem<'_>>>
Looks up a PDG item by name.
Items include particles, groups, aliases, charge multiplets, and other names used to organize decays.
§Errors
Returns a database error if the query cannot be executed.
Sourcepub fn item_children(
&self,
name: impl Into<String>,
) -> PdgResult<Vec<PdgItemChild<'_>>>
pub fn item_children( &self, name: impl Into<String>, ) -> PdgResult<Vec<PdgItemChild<'_>>>
Returns child items for a PDG item name.
§Errors
Returns a database error if the item map or particle lookup cannot be queried.
Sourcepub fn item_parents(
&self,
name: impl Into<String>,
) -> PdgResult<Vec<PdgItem<'_>>>
pub fn item_parents( &self, name: impl Into<String>, ) -> PdgResult<Vec<PdgItem<'_>>>
Returns parent items for a PDG item name.
§Errors
Returns a database error if the query cannot be executed.
Sourcepub fn children_for_pdgid(
&self,
pdgid: impl Into<String>,
) -> PdgResult<Vec<PdgIdEntry>>
pub fn children_for_pdgid( &self, pdgid: impl Into<String>, ) -> PdgResult<Vec<PdgIdEntry>>
Returns PDG identifier rows whose parent is pdgid.
§Errors
Returns a database error if the query cannot be executed.
Sourcepub fn mapped_entries_for_pdgid(
&self,
pdgid: impl Into<String>,
) -> PdgResult<Vec<PdgIdEntry>>
pub fn mapped_entries_for_pdgid( &self, pdgid: impl Into<String>, ) -> PdgResult<Vec<PdgIdEntry>>
Returns PDG identifier rows linked from pdgid through the mapping table.
§Errors
Returns a database error if the query cannot be executed.
Sourcepub fn data_for(
&self,
pdgid: impl Into<String>,
) -> PdgResult<Vec<DataEntry<'_>>>
pub fn data_for( &self, pdgid: impl Into<String>, ) -> PdgResult<Vec<DataEntry<'_>>>
Returns latest-edition numeric data rows for a PDG identifier.
§Errors
Returns a database error if the query cannot be executed.
Sourcepub fn texts_for(&self, pdgid: impl Into<String>) -> PdgResult<Vec<PdgText>>
pub fn texts_for(&self, pdgid: impl Into<String>) -> PdgResult<Vec<PdgText>>
Returns text blocks attached to a PDG identifier.
§Errors
Returns a database error if the query cannot be executed.
Sourcepub fn footnotes_for(
&self,
pdgid: impl Into<String>,
) -> PdgResult<Vec<PdgFootnote>>
pub fn footnotes_for( &self, pdgid: impl Into<String>, ) -> PdgResult<Vec<PdgFootnote>>
Returns footnotes attached to a PDG identifier.
§Errors
Returns a database error if the query cannot be executed.
Sourcepub fn measurements_for(
&self,
pdgid: impl Into<String>,
) -> PdgResult<Vec<PdgMeasurement>>
pub fn measurements_for( &self, pdgid: impl Into<String>, ) -> PdgResult<Vec<PdgMeasurement>>
Returns measurement rows, values, references, and footnotes for a PDG identifier.
§Errors
Returns a database error if measurement, value, or footnote queries cannot be executed.