Function enso_prelude::with[][src]

pub fn with<T, F: FnOnce(T) -> Out, Out>(t: T, f: F) -> Out
Expand description

Surprisingly useful function. Consider the following code:

fn init(self) -> Self {
   let mut data = self.borrow_mut();
   ...
   self
   }

It may not compile telling that the last line moves self out, however, borrow might be used there, when data is dropped and runs the destructor.

We can use this function to narrow-down the lifetimes. The following code compiles just fine:

fn init(self) -> Self {
   with(self.borrow_mut(), |mut data| {
       ...
   });
   self
   }