facet-maybe-mut
Development of this crate is supported by MHC Solutions GmbH, an engineering company focused on building, industrial, and energy automation whose support for open-source work helps make projects like this possible.
Utility crate for working with facet values that may be readonly (Peek) or mutable (Poke), including values behind lockable pointer types like Arc<RwLock<T>> and Arc<Mutex<T>>.
MaybeMut is useful when you want one code path that can inspect values and mutate when possible.
Installation
[]
= "0.0.2"
= "0.46"
= "0.46"
Example: mutate through Arc<RwLock<T>>
use ;
use Facet;
use MaybeMut;
use Peek;
let value = new;
let mut guard = Not.write.unwrap;
if let Mut = &mut *guard
Example: read with automatic lock handling
use ;
use Facet;
use MaybeMut;
use Peek;
let value = new;
let guard = Not.read.unwrap;
let age = guard.as_peek..unwrap.age;
assert_eq!;
Notes
This crate intentionally trades ergonomics for strict control over locking details. In hot paths, prefer more explicit access patterns.
Also, this crate contains unsafe code which may not be sound.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.