reft

Crates.ioreft
lib.rsreft
version0.2.0
created_at2025-06-19 12:03:12.301009+00
updated_at2025-06-19 13:34:35.0136+00
descriptionRef and Mut wrappers that implement AsRef and AsMut for any given &T
homepage
repository
max_upload_size
id1718260
size21,064
(iizudev)

documentation

README

reft

The Problem

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!
}

How to use

Add this to your Cargo.toml:

[dependencies]
reft = "*" # check for the latest version at crates.io

Or run:

cargo add reft

How to contribute

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.

License

This project is dual-licensed under:

You may choose either license at your option.

Commit count: 0

cargo fmt