Skip to main content

Pdg

Struct Pdg 

Source
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

Source

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.

Source

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.

Source

pub fn open_path(path: impl AsRef<Path>) -> PdgResult<Self>

Opens a PDG SQLite database at path.

This is useful for applications that manage their own database file or want to use a different PDG edition. Use Pdg::open for the default cache-or-download behavior.

§Errors

Returns a database error if path cannot be opened or initialized.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for Pdg

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Pdg

§

impl !RefUnwindSafe for Pdg

§

impl !Sync for Pdg

§

impl !UnwindSafe for Pdg

§

impl Send for Pdg

§

impl Unpin for Pdg

§

impl UnsafeUnpin for Pdg

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

type Output = T

Should always be Self
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.