| Crates.io | reft |
| lib.rs | reft |
| version | 0.2.0 |
| created_at | 2025-06-19 12:03:12.301009+00 |
| updated_at | 2025-06-19 13:34:35.0136+00 |
| description | Ref and Mut wrappers that implement AsRef and AsMut for any given &T |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1718260 |
| size | 21,064 |
Rust's AsRef<T> (as well as AsMut<T>) isn't implemented for &T (or &mut T).
Rust's borrowing system is powerful, but sometimes we need to abstract over references without tying our code to &T
struct MyStruct;
fn do_something<T: AsRef<MyStruct>>(t: T) {
todo!("do something very generic")
}
fn main() {
let t = MyStruct;
do_something(&t); // -> Won't compile, since AsRef is not implemented for &MyStruct!
do_something(reft::Ref::new(&t)); // -> Now works!
}
Add this to your Cargo.toml:
[dependencies]
reft = "*" # check for the latest version at crates.io
Or run:
cargo add reft
Fork repository, make changes, and send us a pull request.
We will review your changes and apply them to the main branch shortly, provided they don't violate our quality standards.
This project is dual-licensed under:
You may choose either license at your option.