Skip to main content

RuleSetCache

Struct RuleSetCache 

Source
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

Source

pub fn new() -> Result<Self, Error>

The cache in the default directory (RuleSetCache::default_dir).

§Errors

As RuleSetCache::default_dir.

Source

pub fn at(root: impl Into<PathBuf>) -> Self

The cache in the directory root (created when something is fetched).

Source

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.

Source

pub fn root(&self) -> &Path

The cache directory.

Source

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.

Source

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.

Source

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.

Source

pub fn load_rule_set( &self, rule_set: &FetchedRuleSet, ) -> Result<Validator, Error>

Loads rule_set from the cache, as RuleSetCache::load.

§Errors

As RuleSetCache::load.

Source

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

Removes everything this crate put in the cache: the bundles, the downloads, the tools and the temporary files (and the directory itself, when nothing else is in it). Other files in the directory are left alone.

§Errors

Error::Io when something cannot be removed.

Trait Implementations§

Source§

impl Clone for RuleSetCache

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RuleSetCache

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.