#![cfg_attr(not(feature = "std"), no_std)] #![allow(dead_code)] // some code is tested for type checking only #[cfg(not(feature = "std"))] extern crate alloc; #[cfg(not(feature = "std"))] use ::alloc::{boxed::Box, vec::Vec}; use derive_more::Deref; #[derive(Deref)] #[deref(forward)] struct MyBoxedInt(Box); #[derive(Deref)] #[deref(forward)] struct NumRef<'a> { num: &'a i32, } #[derive(Deref)] struct NumRef2<'a> { #[deref(forward)] num: &'a i32, useless: bool, } #[derive(Deref)] #[deref(forward)] struct NumRef3<'a> { num: &'a i32, #[deref(ignore)] useless: bool, } #[derive(Deref)] struct MyInt(i32); #[derive(Deref)] struct Point1D { x: i32, } #[derive(Deref)] struct Point1D2 { x: i32, #[deref(ignore)] useless: bool, } #[derive(Deref)] struct CoolVec { cool: bool, #[deref] vec: Vec, } #[derive(Deref)] struct GenericVec(Vec); #[test] fn deref_generic() { let gv = GenericVec(Vec::::new()); assert!(gv.is_empty()) } #[derive(Deref)] struct GenericBox(#[deref(forward)] Box); #[test] fn deref_generic_forward() { let boxed = GenericBox(Box::new(1i32)); assert_eq!(*boxed, 1i32); }