Skip to main content

PrivacyBudget

Struct PrivacyBudget 

Source
pub struct PrivacyBudget { /* private fields */ }
👎Deprecated since 0.4.0:

not differentially private (predictable xorshift64 state, time-derived seed, floating-point inverse transform); use alice_crypto::dp instead. Removed in 0.5.0

Expand description

Track cumulative privacy budget (composition theorem)

Under sequential composition, ε values add up. Under parallel composition over disjoint data, use max.

Implementations§

Source§

impl PrivacyBudget

Source

pub const fn new(max_epsilon: f64) -> Self

Create a new privacy budget tracker

Source

pub fn try_spend(&mut self, epsilon: f64) -> bool

Try to spend epsilon from budget

Returns true and charges the ledger if the request is well formed and fits in the remaining budget; returns false and leaves every field untouched otherwise.

A request is well formed when epsilon is finite and not negative. 0.0 (and -0.0) is well formed: it charges nothing and counts a query.

Rejecting a negative epsilon is the whole point of the type. Until 2026-10-07 the guard was only the budget comparison total + epsilon <= max, which a negative value passes trivially, so try_spend(-10.0) returned true and raised the remaining budget from 1 to 11; -inf raised it to infinity. A caller that spends a negative epsilon between two honest queries escapes the limit the budget exists to enforce. NaN and +inf were already refused, though only as a side effect of the comparison being false — they are now refused by the same explicit check.

Source

pub fn remaining(&self) -> f64

Get remaining budget

Source

pub const fn spent(&self) -> f64

Get total spent

Source

pub const fn query_count(&self) -> u64

Get query count

Source

pub fn is_exhausted(&self) -> bool

Check if budget is exhausted

Source

pub const fn reset(&mut self)

Reset the budget

Trait Implementations§

Source§

impl Clone for PrivacyBudget

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 PrivacyBudget

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