Struct uniffi::ffi::handle_maps::ArcHandleMap [−][src]
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]
impl<T: Sync + Send> ArcHandleMap<T>
[src]pub fn len(&self) -> usize
[src]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
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]
&self,
out_error: &mut ExternError,
h: u64,
callback: F
) -> R::Value where
F: UnwindSafe + FnOnce(&T) -> Result<R, E>,
ExternError: From<E>,
R: IntoFfi,
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]
&self,
out_error: &mut ExternError,
h: u64,
callback: F
) -> R::Value where
F: UnwindSafe + FnOnce(&T) -> R,
R: IntoFfi,