Crates.io | ref_wrapper |
lib.rs | ref_wrapper |
version | 0.2.2 |
source | src |
created_at | 2023-04-06 03:37:47.270339 |
updated_at | 2024-02-16 10:20:31.835946 |
description | Wrapper of dynamically borrowed data. |
homepage | |
repository | https://github.com/nossie531/ref_wrapper |
max_upload_size | |
id | 831909 |
size | 23,541 |
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 |
RefWrapMut |
RefMut |
Normal use case.
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.
let src = RefCell::new(vec![1, 2, 3]);
let iter = RefWrap::new(src.borrow(), |x| x.iter());
assert_eq!(iter.sum::<i32>(), 6);
v0.2.2
RefIter::new
and RefIterMut::new
.v0.2.1
v0.2.0
no_std
.new
method callback argument returns no longer need to wrapped in Box
.RefWrap
and RefWrapMut
implement Iterator
in certain cases.RefIter
and RefIterMut
have been removed.v0.1.3-0.1.5
v0.1.2