Crates.io | borrow_trait |
lib.rs | borrow_trait |
version | 0.1.1 |
source | src |
created_at | 2019-07-31 09:52:13.35313 |
updated_at | 2019-08-13 10:29:43.688146 |
description | Exposes traits for `borrow` and `borrow_mut`. |
homepage | |
repository | https://github.com/Luro02/borrow_trait |
max_upload_size | |
id | 153174 |
size | 18,935 |
This library provides traits for borrow
and borrow_mut
functions, most commonly found in RefCell
s. Therefore it is possible to accept other kinds of RefCell
s like an AtomicRefCell
or smart pointers around RefCell
s like Arc
, Rc
or Box
.
use std::io::{ Read, Cursor };
use std::cell::RefCell;
use borrow_trait::{ BorrowRefMut };
fn takes_bound<C, T>(value: &T) -> Vec<u8>
where
T: for<'a> BorrowRefMut<'a, Target = C>,
C: Read,
{
let mut result = vec![];
value.borrow_mut().read_to_end(&mut result).expect("Failed to read from `value: T`");
result
}
let value = RefCell::new(Cursor::new(vec![0, 1, 2, 3]));
assert_eq!(takes_bound(&value), vec![0, 1, 2, 3]);
For more details please refer to the documentation, that you can find here: https://docs.rs/borrow_trait
Simply add the following line to your Cargo.toml
under [dependencies]
:
borrow_trait = { version = "0.1" }
BorrowRef<'a, C, T>
and BorrowRefMut<'a, C, T>
.
This feature requires Generic Associated Lifetimes
rust-lang/rust#44265This project is licensed under either of
at your option.
If you have any issue please don't hesitate to create one :)
Before you make a PR please ensure, that your code has been formatted with rustfmt
:
cargo fmt