Skip to main content

SharedGuard

Struct SharedGuard 

Source
pub struct SharedGuard<T> { /* private fields */ }
Expand description

Specialized guard for managing shared state

This guard is useful for managing Arc<Mutex> resources where you want to ensure proper locking and unlocking.

Implementations§

Source§

impl<T> SharedGuard<T>

Source

pub fn new(resource: Arc<Mutex<T>>) -> Self

Create a new shared guard

§Arguments
  • resource: The Arc<Mutex> to manage
§Example
use foundation_utils::raii::SharedGuard;
use std::sync::{Arc, Mutex};

let shared_data = Arc::new(Mutex::new(42));
let _guard = SharedGuard::new(shared_data);
// Mutex is automatically handled
Source

pub fn lock( &mut self, ) -> Result<MutexGuard<'_, T>, PoisonError<MutexGuard<'_, T>>>

Lock the mutex and get a reference to the data

This is a convenience method that handles the lock/unlock pattern

Source

pub fn resource(&self) -> &Arc<Mutex<T>>

Get the shared resource without locking

Trait Implementations§

Source§

impl<T> Drop for SharedGuard<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for SharedGuard<T>

§

impl<T> RefUnwindSafe for SharedGuard<T>

§

impl<T> Send for SharedGuard<T>
where T: Send,

§

impl<T> Sync for SharedGuard<T>
where T: Send,

§

impl<T> Unpin for SharedGuard<T>

§

impl<T> UnsafeUnpin for SharedGuard<T>

§

impl<T> UnwindSafe for SharedGuard<T>

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> IntoScoped for T

Source§

type Resource = T

Source§

fn into_scoped(self) -> <T as IntoScoped>::Resource

Convert into a scoped resource
Source§

fn scoped<F, R>(self, f: F) -> R
where Self: Sized, F: FnOnce(&Self::Resource) -> R,

Execute a scoped operation with this resource
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.