Expand description
§Own or borrow your data.
This crate provides the OwnOrBorrow type that wraps either owned data or a RefCell
borrowed reference to it. Think Cow for borrowing.
§no_std vs. std
To use the crate in a no_std context, disable the std feature.
§Crate features
std- Enablesstd; disabling entersno_stdmode.defmt- Enables deferred formatting support via the defmt crate.
§Examples
You can create an OwnOrBorrow from an owned value:
use own_or_borrow::OwnOrBorrow;
let mut value = OwnOrBorrow::own(42);
assert_eq!(value.borrow().as_ref(), &42);
assert_eq!(value.borrow_mut().as_mut(), &mut 42);You can create an OwnOrBorrow from a RefCell and treat it the same way:
use own_or_borrow::OwnOrBorrow;
use core::cell::RefCell;
let refcell = RefCell::new(42);
let mut value = OwnOrBorrow::from(refcell);
assert_eq!(value.borrow().as_ref(), &42);
assert_eq!(value.borrow_mut().as_mut(), &mut 42);Enums§
- OwnOr
Borrow - A type that provides either an owned value or
RefCellborrowed reference to a value. - Reference
- A reference to borrowed or owned data.
- Reference
Mut - A mutable reference to borrowed or owned data.
- TryInto
Error - Errors from
TryIntotraits and related.