Skip to main content

QuotaPermit

Struct QuotaPermit 

Source
pub struct QuotaPermit(/* private fields */);
Expand description

Proof that a file’s size was successfully reserved against a [QuotaTracker].

This is a capability token, not a data type: it carries no payload and exists only so that code holding one can prove a tracker actually authorized the charge. Its only producer is [QuotaTracker::reserve] — the private field means no other code, in or out of this crate, can assemble one directly. EntryValidator exposes three ways to obtain one, all funneling through that same reserve call: EntryValidator::validate_entry embeds it in ValidatedEntryType::File for the common case where path validation and quota reservation happen together; its crate-private reserve_hardlink and reserve_file methods return it standalone for callers that must decouple the two — hardlinks (target size only known in a second pass) and 7z’s duplicate-skip check (quota must not be reserved for an entry that turns out to be a skipped duplicate), respectively.

Deliberately not Clone/Copy/Default: a permit represents a single reservation and must not be duplicated or spent more than once. Zero-sized (PhantomData-based), so wrapping it in Result costs nothing over Result<()>.

§Examples

The common case: a QuotaPermit arrives already embedded in a validated file entry, via EntryValidator::validate_entry:

use exarch_core::SecurityConfig;
use exarch_core::security::EntryValidator;
use exarch_core::security::ValidatedEntryType;
use exarch_core::types::DestDir;
use exarch_core::types::EntryType;
use std::path::Path;
use std::path::PathBuf;

let dest = DestDir::new(PathBuf::from("/tmp"))?;
let config = SecurityConfig::default().validate()?;
let mut validator = EntryValidator::new(&config, &dest);

let entry = validator.validate_entry(
    Path::new("file.txt"),
    &EntryType::File,
    1024, // uncompressed size
    None, // compressed size
    None, // mode
    None, // dir_cache
)?;

if let ValidatedEntryType::File(permit) = entry.entry_type() {
    println!("{permit:?}");
}

Trait Implementations§

Source§

impl Debug for QuotaPermit

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