SHARE
TWEET

Untitled

a guest Jan 18th, 2020 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pub enum Workload<T> {
  2.   Done(T),
  3.   More(Box<dyn FnOnce() -> Workload<T>>)
  4. }
  5.  
  6. impl<T> Workload<T> {
  7.  
  8.   pub fn done(t: T) -> Workload<T> {
  9.     Workload::Done(t)
  10.   }
  11.  
  12.   pub fn more<K: FnOnce() -> Workload<T>>(k: K) -> Self {
  13.     Workload::More(Box::new(k))
  14.   }
  15.  
  16.   pub fn bind<U, K: FnOnce(&mut T) -> Workload<U>>(&mut self, next: K) -> Workload<U> {
  17.     match self {
  18.       Workload::Done(val) => next(val),
  19.       Workload::More(fun) => fun().bind(next)
  20.     }
  21.   }
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top