1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*! 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 Allows access to dynamically borrowed data ([`Ref`][Ref] or [`RefMut`][RefMut])
with a given wrapper type. For example, this makes it possible to generate iterators
for handling the borrowed data. Note that the original borrowing is consumed and
taken into the wrapper type. Therefore, when the wrapper is dropped, the original
borrowing is also dropped.
[Ref]: std::cell::Ref
[RefMut]: std::cell::RefMut
# Examples
Normal use case.
```
# use ref_wrapper::RefWrap;
# use std::cell::{Ref, RefCell};
#
let vec = RefCell::new(vec![1, 2, 3]);
let summary = extract_summary(vec.borrow());
assert_eq!(*summary, 6);
fn extract_summary(src: Ref<Vec<i32>>) -> RefWrap<'_, i32> {
RefWrap::new(src, |x| Box::new(x.iter().sum()))
}
```
Iterator use case.
```
# use ref_wrapper::{RefIter, RefWrap};
# use std::cell::{Ref, RefCell};
#
let vec = RefCell::new(vec![1, 2, 3]);
let iter = extract_iter(vec.borrow());
assert_eq!(iter.sum::<i32>(), 6);
fn extract_iter(src: Ref<Vec<i32>>) -> RefIter<'_, &i32> {
RefIter::new(src, |x| Box::new(x.iter()))
}
```
*/
pub use RefIter;
pub use RefIterMut;
pub use RefWrap;
pub use RefWrapMut;
use reset_mut_lifetime;
use reset_ref_lifetime;