1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
//! # `auto_ref`
//!
//! Attributes for replace reference parameter `&T` to `impl AsRef<T>` or `impl Borrow<T>`
//!
//! ## Usage
//!
//! ```rs
//! 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
//!
//! ```rs
//! 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);
//! }
//! ```
use proc_macro::TokenStream;
#[proc_macro_attribute]
pub fn auto_ref(attr: TokenStream, item: TokenStream) -> TokenStream {
auto_ref_impl::auto_ref(attr.into(), item.into()).into()
}
#[proc_macro_attribute]
pub fn auto_borrow(attr: TokenStream, item: TokenStream) -> TokenStream {
auto_ref_impl::auto_borrow(attr.into(), item.into()).into()
}