Skip to main content

PackageHelpDb

Struct PackageHelpDb 

Source
pub struct PackageHelpDb { /* private fields */ }
Expand description

A reader over an installed R package’s compiled help database: help/<pkg>.rdx + help/<pkg>.rdb, plus the sibling help/aliases.rds and Meta/hsearch.rds files.

The .rdx index is parsed eagerly at PackageHelpDb::open (it’s small); .rdb records are read on demand by seeking into the .rdb file, since records are independent and there’s no need to hold the whole file in memory. help/aliases.rds is parsed lazily, on the first call to PackageHelpDb::aliases or PackageHelpDb::resolve_alias, and the resulting index is cached for the lifetime of this reader – a failed parse is NOT cached, so a transient failure (a missing or momentarily corrupt file) is retried on the next call rather than poisoning every subsequent lookup. A duplicated alias resolves to its LAST occurrence, matching the last-wins semantics of R’s own list2env()-based alias loader; PackageHelpDb::aliases still returns every entry, including duplicates, in on-disk order, since that’s what oracle comparisons against R’s readRDS() expect. search_index() re-reads Meta/hsearch.rds on every call rather than caching – it’s read infrequently relative to alias/topic lookups, and re-reading keeps the API simple and always up to date.

Implementations§

Source§

impl PackageHelpDb

Source

pub fn open(pkg_dir: impl AsRef<Path>) -> Result<Self, Error>

Opens <pkg_dir>/help/<pkg>.rdx (+ .rdb), where <pkg> is the basename of pkg_dir, e.g. /opt/R/4.6.1/lib/R/library/utils.

Library-path discovery (R’s .libPaths()) is out of scope: callers must supply the installed package directory explicitly.

Source

pub fn package(&self) -> &str

The package name (the basename of the directory passed to PackageHelpDb::open).

Source

pub fn topics(&self) -> impl Iterator<Item = &str>

Topic names present in the .rdx variables map, in index order.

Source

pub fn reference_keys(&self) -> impl Iterator<Item = &str>

Persistence keys present in the .rdx references map (e.g. "env::0"), in index order.

Source

pub fn raw_topic(&self, topic: &str) -> Result<RObject, Error>

Raw decoded Rd object for topic: a .rdx variables lookup, a .rdb record fetch, zlib decompression, and rd_rds::parse.

Source

pub fn reference(&self, key: &str) -> Result<RObject, Error>

Fetches a record via the .rdx references map (persistence keys like "env::0"). Same mechanics as PackageHelpDb::raw_topic, different key space.

rd-helpdb does not attempt to resolve PERSISTSXP nodes into environments; this only exposes the raw record a reference key points at.

Source

pub fn aliases(&self) -> Result<Vec<(String, String)>, Error>

alias -> topic map from help/aliases.rds, in on-disk order, including duplicate aliases if the file has any (see the struct-level docs for how PackageHelpDb::resolve_alias handles duplicates).

Source

pub fn resolve_alias(&self, alias: &str) -> Result<Option<&str>, Error>

Resolves alias to its topic name via help/aliases.rds. If alias occurs more than once in the file, resolves to the topic of its LAST occurrence, matching R’s own list2env()-based alias loader.

Source

pub fn search_index(&self) -> Result<RObject, Error>

Decoded Meta/hsearch.rds as a raw RObject (no typed model yet).

Trait Implementations§

Source§

impl Debug for PackageHelpDb

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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, 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.