2 releases
0.1.1 | Aug 13, 2020 |
---|---|
0.1.0 | Aug 13, 2020 |
#17 in #borrowed
32 downloads per month
Used in 2 crates
(via mtots_core)
9KB
200 lines
XRef and XRefMut
When you want to return some data that might be either
owned or borrowed, it is common to return a Cow<T>
.
However, Cow<T>
has the following limitations:
T
has to beToOwned
, and- if the data you want to borrow is behind a
RefCell
, you can't.
XRef<T>
is like Cow<T>
, except addresses the above
limitations with the following differences:
T
does not have to beToOwned
, (this means that now the type contained inBorrowed
andOwned
have to contain the exact matching types), andXRef<T>
has a third variantRef
which holds astd::cell::Ref<T>
, for cases when the value is borrowed from aRefCell
.
XRefMut<T>
is like XRef<T>
except that
- all references are borrowed mutably (i.e.
XRef::Borrowed
holds a&mut T
instead of&T
,XRef::Ref
holds aRefMut<T>
instead of aRef<T>
), XRefMut<T>
implementsDerefMut<T>
, to allow borrowing data mutably without cloning.