pub struct RuleSetCache { /* private fields */ }Expand description
The cache of the rule sets fetched from their publishers (fetched_rule_sets):
a directory holding, under rules/, the bundle of each fetched rule set, laid out
as the fetch scripts of the repository lay them out
(FetchedRuleSet::bundle_path).
The default directory is the platform’s cache directory: $XDG_CACHE_HOME, else
~/.cache, on Linux and the BSDs; ~/Library/Caches on macOS; %LOCALAPPDATA% on
Windows (with einvoice-validator/ under it, and cache/ under that on Windows);
the environment variable CACHE_ENV (EINVOICE_VALIDATOR_CACHE) overrides it.
Nothing is ever downloaded except by RuleSetCache::fetch (feature fetch):
loading a rule set that is not in the cache is Error::NotCached. A loaded rule
set is checked in full on every load: its manifest must be, byte for byte, the one
the catalogue of this version gives, and every file must have the SHA-256 that
manifest records, so a cache can be used offline and is never trusted.
Implementations§
Source§impl RuleSetCache
impl RuleSetCache
Sourcepub fn new() -> Result<Self, Error>
pub fn new() -> Result<Self, Error>
The cache in the default directory (RuleSetCache::default_dir).
§Errors
Sourcepub fn at(root: impl Into<PathBuf>) -> Self
pub fn at(root: impl Into<PathBuf>) -> Self
The cache in the directory root (created when something is fetched).
Sourcepub fn default_dir() -> Result<PathBuf, Error>
pub fn default_dir() -> Result<PathBuf, Error>
The default cache directory: CACHE_ENV when it is set and not empty, else
the platform’s cache directory (see RuleSetCache).
§Errors
Error::Fetch when there is no home or cache directory to put it in.
Sourcepub fn bundle_dir(&self, rule_set: &FetchedRuleSet) -> PathBuf
pub fn bundle_dir(&self, rule_set: &FetchedRuleSet) -> PathBuf
The directory of the bundle of rule_set in the cache, whether it is there or
not: what einvoice-validate --bundle takes.
Sourcepub fn status(&self, rule_set: &FetchedRuleSet) -> CacheStatus
pub fn status(&self, rule_set: &FetchedRuleSet) -> CacheStatus
What the cache holds of rule_set: its manifest and every file it names are
checked (read and hashed), the stylesheets are not prepared.
Sourcepub fn load(&self, name: &str) -> Result<Validator, Error>
pub fn load(&self, name: &str) -> Result<Validator, Error>
Loads the fetched rule set name (or the alias peppol) from the cache.
§Errors
Error::Bundle for a name that is no fetched rule set; Error::NotCached
when it has not been fetched; Error::Bundle when the cache holds something
else in its place (a manifest that is not the catalogue’s), and otherwise as
Validator::from_bundle_dir, which checks the SHA-256 of every file.