Struct uniffi::ffi::handle_maps::ArcHandleMap[][src]

pub struct ArcHandleMap<T> where
    T: Sync + Send
{ pub map: RwLock<HandleMap<Arc<T>>>, }
Expand description

ArcHandleMap is a relatively thin wrapper around RwLock<HandleMap<Arc<T>>>. This is only suitable for objects that implement Sync and Send and is for objects that are able to look after their own locking, and need to be called from multiple foreign language threads at the same time.

In contrast, the ConcurrentHandleMap is aliased as MutexHandleMap to show the difference: objects with mut methods can be used, but the objects can only be accessed from one thread at a time.

The Threadsafe annotation is used to choose which handle map uniffi uses.

This module also provides the UniffiMethodCall trait, which allows generated scaffolding to switch almost seemlessly.

Fields

map: RwLock<HandleMap<Arc<T>>>

The underlying map. Public so that more advanced use-cases may use it as they please.

Implementations

impl<T: Sync + Send> ArcHandleMap<T>[src]

pub fn new() -> Self[src]

Construct a new ArcHandleMap.

pub fn len(&self) -> usize[src]

Get the number of entries in the ArcHandleMap.

This takes the map’s read lock.

pub fn is_empty(&self) -> bool[src]

Returns true if the ArcHandleMap is empty.

This takes the map’s read lock.

pub fn insert(&self, v: T) -> Handle[src]

Insert an item into the map, returning the newly allocated handle to the item.

This takes the map’s write lock which the object is inserted.

pub fn delete(&self, h: Handle) -> Result<(), HandleError>[src]

Remove an item from the map.

This takes the map’s write lock while removing from the map, but not while the object is being dropped.

pub fn delete_u64(&self, h: u64) -> Result<(), HandleError>[src]

Convenient wrapper for delete which takes a u64 that it will convert to a handle.

The main benefit (besides convenience) of this over the version that takes a Handle is that it allows handling handle-related errors in one place.

pub fn remove(&self, h: Handle) -> Result<Option<T>, HandleError>[src]

Remove an item from the map, returning either the item, or None if its guard mutex got poisoned at some point.

This takes the map’s write lock, and unwraps the Arc.

pub fn remove_u64(&self, h: u64) -> Result<Option<T>, HandleError>[src]

Convenient wrapper for remove which takes a u64 that it will convert to a handle.

The main benefit (besides convenience) of this over the version that takes a Handle is that it allows handling handle-related errors in one place.

pub fn get<F, E, R>(&self, h: Handle, callback: F) -> Result<R, E> where
    F: FnOnce(&T) -> Result<R, E>,
    E: From<HandleError>, 
[src]

Call callback with a non-mutable reference to the item from the map, after acquiring the necessary locks.

This takes the map’s read lock for as long as needed to clone the inner Arc. This is so the lock isn’t held while the callback is in use.

This takes the map’s read lock for as long as needed to clone the inner Arc. This is so the lock isn’t held while the callback is in use.

pub fn get_u64<F, E, R>(&self, u: u64, callback: F) -> Result<R, E> where
    F: FnOnce(&T) -> Result<R, E>,
    E: From<HandleError>, 
[src]

Convenient wrapper for get which takes a u64 that it will convert to a handle.

The other benefit (besides convenience) of this over the version that takes a Handle is that it allows handling handle-related errors in one place.

This takes the map’s read lock for as long as needed to clone the inner Arc. This is so the lock isn’t held while the callback is in use.

pub fn call_with_result<R, E, F>(
    &self,
    out_error: &mut ExternError,
    h: u64,
    callback: F
) -> R::Value where
    F: UnwindSafe + FnOnce(&T) -> Result<R, E>,
    ExternError: From<E>,
    R: IntoFfi
[src]

Helper that performs both a [call_with_result] and get.

This takes the map’s read lock for as long as needed to clone the inner Arc. This is so the lock isn’t held while the callback is in use.

pub fn call_with_output<R, F>(
    &self,
    out_error: &mut ExternError,
    h: u64,
    callback: F
) -> R::Value where
    F: UnwindSafe + FnOnce(&T) -> R,
    R: IntoFfi
[src]

Helper that performs both a [call_with_output] and get.

pub fn insert_with_result<E, F>(
    &self,
    out_error: &mut ExternError,
    constructor: F
) -> u64 where
    F: UnwindSafe + FnOnce() -> Result<T, E>,
    ExternError: From<E>, 
[src]

Use constructor to create and insert a T, while inside a [call_with_result] call (to handle panics and map errors onto an ExternError).

This takes the map’s write lock for as long as needed to insert into the map. This is so the lock isn’t held while the constructor is being called.

pub fn insert_with_output<F>(
    &self,
    out_error: &mut ExternError,
    constructor: F
) -> u64 where
    F: UnwindSafe + FnOnce() -> T, 
[src]

Equivalent to insert_with_result for the case where the constructor cannot produce an error.

The name is somewhat dubious, since there’s no output, but it’s intended to make it clear that it contains a [call_with_output] internally.

impl<T: Sync + Send> ArcHandleMap<T>[src]

The faux implementation of UniffiMethodCall which differs from the real one by not requiring mut references to T.

pub fn method_call_with_result<R, E, F>(
    &self,
    out_error: &mut ExternError,
    h: u64,
    callback: F
) -> R::Value where
    F: UnwindSafe + FnOnce(&T) -> Result<R, E>,
    ExternError: From<E>,
    R: IntoFfi
[src]

pub fn method_call_with_output<R, F>(
    &self,
    out_error: &mut ExternError,
    h: u64,
    callback: F
) -> R::Value where
    F: UnwindSafe + FnOnce(&T) -> R,
    R: IntoFfi
[src]

Trait Implementations

impl<T: Sync + Send> Default for ArcHandleMap<T>[src]

fn default() -> Self[src]

Returns the “default value” for a type. Read more

Auto Trait Implementations

impl<T> RefUnwindSafe for ArcHandleMap<T>

impl<T> Send for ArcHandleMap<T>

impl<T> Sync for ArcHandleMap<T>

impl<T> Unpin for ArcHandleMap<T>

impl<T> UnwindSafe for ArcHandleMap<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.