auto_ref 0.1.2

Replace &T to impl AsRef<T>.
Documentation
  • Coverage
  • 33.33%
    1 out of 3 items documented0 out of 2 items with examples
  • Size
  • Source code size: 7.98 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 278.46 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 4s Average build duration of successful builds.
  • all releases: 4s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • kazatsuyu/auto_ref
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • kazatsuyu

auto_ref

Attributes for replace reference parameter &T to impl AsRef<T> or impl Borrow<T>

Usage

use auto_ref::{auto_ref, auto_borrow};

#[auto_ref]
fn example1(s: &str, t: &mut str) {
    println!("{}, {}", s, t);
}

#[auto_borrow]
fn example2(s: &str, t: &mut str) {
    println!("{}, {}", s, t);
}

#[auto_ref(s)]
#[auto_borrow(t)]
fn example3(s: &str, t: &str) {
    println!("{}, {}", s, t);
}

The above code is convert to

fn example1(s: impl ::core::convert::AsRef<str>, t: impl ::core::convert::AsMut<str>) {
    let s: &str = s.as_ref();
    let t: &mut str = t.as_mut();
    println!("{}, {}", s, t);
}

fn example2(s: impl ::core::borrow::Borrow<str>, t: impl ::core::borrow::BorrowMut<str>) {
    let s: &str = s.borrow();
    let t: &mut str = t.borrow_mut();
    println!("{}, {}", s, t);
}

fn example3(s: impl ::core::convert::AsRef<str>, t: impl ::core::borrow::Borrow<str>) {
    let t: &str = t.borrow();
    let s: &str = s.as_ref();
    println!("{}, {}", s, t);
}