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:?}");
}