reft 0.2.0

Ref and Mut wrappers that implement AsRef and AsMut for any given &T
Documentation
  • Coverage
  • 100%
    15 out of 15 items documented0 out of 14 items with examples
  • Size
  • Source code size: 21.06 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 437.66 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • iizudev

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.