ref_wrapper
Wrapper of dynamically borrowed data.
The author of this crate is not good at English.
Forgive me if the document is hard to read.
This crate have mainly below items.
Name | Summary |
---|---|
RefWrap |
Wrapper of Ref which can read content from base reference. |
RefWrapMut |
Wrapper of RefMut which can read/write from base reference. |
RefIter |
Type synonim (iterator version of Ref ). |
RefIterMut |
Type synonim (iterator version of RefMut ). |
Examples
Normal use case.
let vec = new;
let sum = extract_summary;
assert_eq!;
Special use case for iterator.
let vec = new;
let mut iter = extract_iter;
assert_eq!;
assert_eq!;
assert_eq!;
Frequent careless mistakes.
When using synonyms for iterators, be careful not to specify the wrong type parameter.
For example, the result type of Vec<T>::iter(&self)
method is Iter<'a, T>
, which
when wrapped becomes RefIter<'a, &T>
. Note the change from T
to &T
. The reason
for this is that the type Iter<'a, T>
implements the trait Iterator<Item = &'a T>
,
and the wrapping target is latter. Although somewhat cumbersome, this allows for the
case where an Iterator's Item is not a reference.