Struct tor_persist::state_dir::InstanceStateHandle

source ·
pub struct InstanceStateHandle { /* private fields */ }
Available on crate feature state-dir only.
Expand description

State or cache directory for an instance of a facility

Implies exclusive access: there is only one InstanceStateHandle at a time, across any number of processes, tasks, and threads, for the same instance.

§Key uniqueness and syntactic restrictions

Methods on InstanceStateHandle typically take a TryIntoSlug.

It is important that keys are distinct within an instance.

Specifically: each key provided to a method on the same InstanceStateHandle (or a clone of it) must be different. Violating this rule does not result in memory-unsafety, but might result in incorrect operation due to concurrent filesystem access, including possible data loss and corruption. (Typically, the key is fixed, and the StorageHandles are usually obtained during instance construction, so ensuring this is straightforward.)

There are also syntactic restrictions on keys. See slug.

Implementations§

source§

impl InstanceStateHandle

source

pub fn storage_handle<T>( &self, key: &(impl TryIntoSlug + ?Sized) ) -> Result<StorageHandle<T>>

Obtain a StorageHandle, usable for storing/retrieving a T

key has syntactic and uniqueness restrictions.

source

pub fn raw_subdir( &self, key: &(impl TryIntoSlug + ?Sized) ) -> Result<InstanceRawSubdir>

Obtain a raw filesystem subdirectory, within the directory for this instance

This API is unsuitable platforms without a filesystem accessible via std::fs. May therefore only be used within Arti for features where we’re happy to not to support such platforms (eg WASM without WASI) without substantial further work.

key has syntactic and uniqueness restrictions.

source

pub fn purge(self) -> Result<()>

Unconditionally delete this instance directory

For expiry, use StateDirectory::purge_instances, and then call this in the dispose method.

Will return a BadAPIUsage if other clones of this InstanceStateHandle exist.

§Deletion is not atomic

If a deletion operation doesn’t complete for any reason (maybe it was interrupted, or there was a filesystem access problem), part of the instance contents may remain.

After such an interrupted deletion, storage items (StorageHandle) are might each independently be deleted (load returns None) or retained (Some).

Deletion of the contents of raw subdirectories (InstanceStateHandle::raw_subdir) is done with std::fs::remove_dir_all. If deletion is interrupted, the raw subdirectory may contain partial contents.

Trait Implementations§

source§

impl Clone for InstanceStateHandle

source§

fn clone(&self) -> InstanceStateHandle

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl ContainsInstanceStateGuard for InstanceStateHandle

source§

fn raw_lock_guard(&self) -> Arc<LockFileGuard>

Obtain a raw clone of the underlying filesystem lock Read more
source§

impl Debug for InstanceStateHandle

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

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

§

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

§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more