pub struct ArcCallable<R, E> { /* private fields */ }Expand description
Thread-safe callable.
ArcCallable<R, E> stores a Arc<Mutex<dyn FnMut() -> Result<R, E> + Send>>
and can be called repeatedly across threads.
§Type Parameters
R- The success value returned by the computation.E- The error value returned when the computation fails.
Implementations§
Source§impl<R, E> ArcCallable<R, E>
impl<R, E> ArcCallable<R, E>
Sourcepub fn new<F>(function: F) -> Self
pub fn new<F>(function: F) -> Self
Creates a new callable.
Wraps the provided closure in the appropriate smart pointer type for this callable implementation.
Examples found in repository?
89fn demo_shared_callable() {
90 println!("--- Shared callable ---");
91
92 let mut call_count = 0;
93 let shared = ArcCallable::new(move || {
94 call_count += 1;
95 Ok::<usize, String>(call_count)
96 });
97
98 let mut first = shared.clone();
99 let mut second = shared.clone();
100 println!("ArcCallable first clone: {:?}", first.call());
101 println!("ArcCallable second clone: {:?}", second.call());
102}Sourcepub fn new_with_name<F>(name: &str, function: F) -> Self
pub fn new_with_name<F>(name: &str, function: F) -> Self
Creates a new named callable.
Wraps the provided closure and assigns it a name, which is useful for debugging and logging purposes.
Sourcepub fn new_with_optional_name<F>(function: F, name: Option<String>) -> Self
pub fn new_with_optional_name<F>(function: F, name: Option<String>) -> Self
Creates a new named callable with an optional name.
Wraps the provided closure and assigns it an optional name.
Sourcepub fn from_supplier<S>(supplier: S) -> Self
pub fn from_supplier<S>(supplier: S) -> Self
Sourcepub fn clear_name(&mut self)
pub fn clear_name(&mut self)
Clears the name of this callable.
Trait Implementations§
Source§impl<R, E> Callable<R, E> for ArcCallable<R, E>
impl<R, E> Callable<R, E> for ArcCallable<R, E>
Source§fn into_local_once(self) -> LocalBoxCallableOnce<R, E>where
Self: Sized + 'static,
fn into_local_once(self) -> LocalBoxCallableOnce<R, E>where
Self: Sized + 'static,
Converts this shared callable into a local boxed one-time callable while preserving its name.
Source§fn to_local_once(&self) -> LocalBoxCallableOnce<R, E>
fn to_local_once(&self) -> LocalBoxCallableOnce<R, E>
Converts this shared callable into a local boxed one-time callable
without consuming self.
Source§fn into_runnable(self) -> BoxRunnable<E>where
Self: Sized + 'static,
fn into_runnable(self) -> BoxRunnable<E>where
Self: Sized + 'static,
Converts this shared callable into a boxed runnable while preserving its name.
Source§fn into_box(self) -> BoxCallable<R, E>where
Self: 'static,
fn into_box(self) -> BoxCallable<R, E>where
Self: 'static,
Source§fn into_rc(self) -> RcCallable<R, E>where
Self: 'static,
fn into_rc(self) -> RcCallable<R, E>where
Self: 'static,
Rc callable. Read moreSource§fn into_arc(self) -> ArcCallable<R, E>
fn into_arc(self) -> ArcCallable<R, E>
Arc callable. Read moreSource§fn into_fn(self) -> impl FnMut() -> Result<R, E>
fn into_fn(self) -> impl FnMut() -> Result<R, E>
Source§fn into_once(self) -> BoxCallableOnce<R, E>where
Self: 'static,
fn into_once(self) -> BoxCallableOnce<R, E>where
Self: 'static,
Source§fn to_box(&self) -> BoxCallable<R, E>where
Self: 'static,
fn to_box(&self) -> BoxCallable<R, E>where
Self: 'static,
self. Read moreSource§fn to_rc(&self) -> RcCallable<R, E>where
Self: 'static,
fn to_rc(&self) -> RcCallable<R, E>where
Self: 'static,
Source§fn to_arc(&self) -> ArcCallable<R, E>
fn to_arc(&self) -> ArcCallable<R, E>
Source§fn to_fn(&self) -> impl FnMut() -> Result<R, E>
fn to_fn(&self) -> impl FnMut() -> Result<R, E>
self. Read moreSource§fn to_once(&self) -> BoxCallableOnce<R, E>where
Self: 'static,
fn to_once(&self) -> BoxCallableOnce<R, E>where
Self: 'static,
self. Read more