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
61
62
63
/*! 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 provide wrappers for value generated from dynamic borrowing types.
| Wrapper | Target |
|----------------|--------------------|
| [`RefWrap`] | [`Ref`][Ref] |
| [`RefWrapMut`] | [`RefMut`][RefMut] |
For example, this makes it possible to generate iterators from dynamicaly
borrowed values. 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]: core::cell::Ref
[RefMut]: core::cell::RefMut
# Examples
Normal use case.
```
# use ref_wrapper::{RefWrap};
# use core::cell::{Ref, RefCell};
# use core::ops::Deref;
#
let src = RefCell::new(vec![1, 2, 3]);
let target = RefWrap::new(src.borrow(), |x| VecStat(x));
assert_eq!(target.summary(), 6);
pub struct VecStat<'a>(&'a Vec<i32>);
impl<'a> VecStat<'a> {
pub fn summary(&self) -> i32 {
self.0.iter().sum::<i32>()
}
}
```
Iterator use case.
```
# use ref_wrapper::RefWrap;
# use core::cell::{Ref, RefCell};
#
let src = RefCell::new(vec![1, 2, 3]);
let iter = RefWrap::new(src.borrow(), |x| x.iter());
assert_eq!(iter.sum::<i32>(), 6);
```
*/
pub use *;
pub use *;
use *;