Crate take_mut

Source
Expand description

This crate provides several functions for handling &mut T including take().

take() allows for taking T out of a &mut T, doing anything with it including consuming it, and producing another T to put back in the &mut T.

During take(), if a panic occurs, the entire process will be aborted, as there’s no valid T to put back into the &mut T. Use take_or_recover() to replace the &mut T with a recovery value before continuing the panic.

Contrast with std::mem::replace(), which allows for putting a different T into a &mut T, but requiring the new T to be available before being able to consume the old T.

Modules§

  • This module provides a scoped API, allowing for taking an arbitrary number of &mut T into T within one closure. The references are all required to outlive the closure.

Functions§

  • Allows use of a value pointed to by &mut T as though it was owned, as long as a T is made available afterwards.
  • Allows use of a value pointed to by &mut T as though it was owned, as long as a T is made available afterwards.