A simple set of macros for the ergonomic shinking of scope.
When doing common operations such as acquiring a Mutex lock or opening a file it can be easy to forget that the lock is held or the file is open for the entirety of the following blocks scope. This crate provides a simple set of macros, influenced by the with statement in Python, that aims to:
```rust use with_api::with;
let mine = "all mine".to_string();
with!(mine, |greedy| { assert!(!greedy.is_empty()); });
// The below fails as its been moved into with! // println!("{:?}", mine); ```
```rust use withapi::borwith;
let immutable: usize = 27;
bor_with!(immutable, |num| { assert!(*num == 27);
// The below fails as it cannot be mutated.
// *num = 28;
}); ```
```rust use withapi::mutwith;
let protec: Mutex
mutwith!(protec.lock().unwrap(), |db| { let _ = db.insert(42, "meaning of life".tostring()); assert!(!db.is_empty());
// lock released at end of scope.
}); ```