[−][src]Struct mula::Mula
State tracker that allows for sharing of a specific computation.
Implementations
impl<T, O, F> Mula<T, O, F> where
T: 'static + Eq + Hash + Clone + Send,
O: 'static + Clone + Send,
F: 'static + Send + Sync + Fn(T) -> O,
[src]
T: 'static + Eq + Hash + Clone + Send,
O: 'static + Clone + Send,
F: 'static + Send + Sync + Fn(T) -> O,
pub fn new(work: F) -> Arc<Self>
[src]
Creates a new Mula
that will own the work
closure.
The return value is wrapped in an std::sync::Arc
so that
you can safely std::sync::Arc::clone()
it to give threads their own reference
of the state tracker.
Note that the work
closure will be called on a separate
thread.
Example:
use mula::Mula; let mula = Mula::new(|input: &str| { std::thread::sleep(std::time::Duration::from_secs(2)); input.to_uppercase() }); // Both of the following call sites will share the same execution // of the closure and get the same result. let m = mula.clone(); std::thread::spawn(move || { let upper = Mula::subscribe_to(m, "mula"); assert_eq!(upper, "MULA".to_string()); }); let upper = Mula::subscribe_to(mula, "mula"); assert_eq!(upper, "MULA".to_string());
pub fn subscribe_to(mula: Arc<Self>, input: T) -> O
[src]
Registers your interest in the output of the computation
defined by the closure provided to Mula::new
and input
.
When this function is called, it will:
- start the computation, if it is not already running for
input
- block and wait for the computation to finish
- return a clone of the result
If your work
closure returns something big, it may be wise
to wrap it on something like an std::sync::Arc
, so that it
isn't deep copied for each of the subscribers.
Example:
use mula::Mula; let mula = Mula::new(|input: &str| { input.to_uppercase() }); let upper = Mula::subscribe_to(mula, "mula"); assert_eq!(upper, "MULA".to_string());
Auto Trait Implementations
impl<T, O, F> !RefUnwindSafe for Mula<T, O, F>
impl<T, O, F> Send for Mula<T, O, F>
impl<T, O, F> Sync for Mula<T, O, F>
impl<T, O, F> Unpin for Mula<T, O, F> where
F: Unpin,
T: Unpin,
F: Unpin,
T: Unpin,
impl<T, O, F> !UnwindSafe for Mula<T, O, F>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,