#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(nightly, feature(never_type))] #![allow(dead_code)] // some code is tested for type checking only
#[cfg(not(feature = "std"))] externcrate alloc;
#[cfg(not(feature = "std"))] use alloc::{borrow::ToOwned, collections::VecDeque, string::String, vec, vec::Vec};
#[cfg(feature = "std")] use std::collections::VecDeque;
// Asserts that the macro expansion doesn't generate a blanket `AsRef` impl forwarding to // the field type, by producing a trait implementations conflict error during compilation, // if it does. impl AsRef<bool> for Types { fn as_ref(&self) -> &bool { self.0.as_ref()
}
}
// Asserts that the macro expansion doesn't generate an `AsRef` impl for the field type, by // producing a trait implementations conflict error during compilation, if it does. impl AsRef<Helper> for Types { fn as_ref(&self) -> &Helper {
&self.0
}
}
#[test] fn types() { let item = Types(Helper(1, 2.0, false));
let rf: &i32 = item.as_ref();
assert!(ptr::eq(rf, item.0.as_ref()));
let rf: &f64 = item.as_ref();
assert!(ptr::eq(rf, item.0.as_ref()));
}
// Asserts that the macro expansion doesn't generate a blanket `AsRef` impl forwarding to // the field type, by producing a trait implementations conflict error during compilation, // if it does. impl AsRef<bool> for TypesWithInner { fn as_ref(&self) -> &bool { self.0.as_ref()
}
}
#[test] fn types_with_inner() { let item = TypesWithInner(Helper(1, 2.0, false));
let rf: &i32 = item.as_ref();
assert!(ptr::eq(rf, item.0.as_ref()));
let rf: &Helper = item.as_ref();
assert!(ptr::eq(rf, &item.0));
}
// Asserts that the macro expansion doesn't generate a blanket `AsRef` impl forwarding to // the field type, by producing a trait implementations conflict error during compilation, // if it does. impl AsRef<bool> for TypesWithRenamedInner { fn as_ref(&self) -> &bool { self.0.as_ref()
}
}
#[test] fn types_with_renamed_inner() { let item = TypesWithRenamedInner(Helper(1, 2.0, false));
let rf: &i32 = item.as_ref();
assert!(ptr::eq(rf, item.0.as_ref()));
let rf: &Helper = item.as_ref();
assert!(ptr::eq(rf, &item.0));
}
// Asserts that the macro expansion doesn't generate a blanket `AsRef` impl forwarding to // the field type, by producing a trait implementations conflict error during compilation, // if it does. impl AsRef<bool> for FieldTypes { fn as_ref(&self) -> &bool { self.0.as_ref()
}
}
// Asserts that the macro expansion doesn't generate an `AsRef` impl for the field type, by // producing a trait implementations conflict error during compilation, if it does. impl AsRef<Helper> for FieldTypes { fn as_ref(&self) -> &Helper {
&self.0
}
}
#[test] fn field_types() { let item = FieldTypes(Helper(1, 2.0, false));
let rf: &i32 = item.as_ref();
assert!(ptr::eq(rf, item.0.as_ref()));
let rf: &f64 = item.as_ref();
assert!(ptr::eq(rf, item.0.as_ref()));
}
// Asserts that the macro expansion doesn't generate a blanket `AsRef` impl forwarding to // the field type, by producing a trait implementations conflict error during compilation, // if it does. impl AsRef<bool> for FieldTypesWithInner { fn as_ref(&self) -> &bool { self.0.as_ref()
}
}
#[test] fn field_types_with_inner() { let item = FieldTypesWithInner(Helper(1, 2.0, false));
let rf: &i32 = item.as_ref();
assert!(ptr::eq(rf, item.0.as_ref()));
let rf: &Helper = item.as_ref();
assert!(ptr::eq(rf, &item.0));
}
// Asserts that the macro expansion doesn't generate a blanket `AsRef` impl forwarding to // the field type, by producing a trait implementations conflict error during compilation, // if it does. impl AsRef<bool> for FieldTypesWithRenamedInner { fn as_ref(&self) -> &bool { self.0.as_ref()
}
}
#[test] fn field_types_with_renamed_inner() { let item = FieldTypesWithRenamedInner(Helper(1, 2.0, false));
let rf: &i32 = item.as_ref();
assert!(ptr::eq(rf, item.0.as_ref()));
let rf: &Helper = item.as_ref();
assert!(ptr::eq(rf, &item.0));
}
mod generic { usesuper::*;
#[derive(AsRef)] struct Nothing<T>(T);
#[test] fn nothing() { let item = Nothing("test".to_owned());
// Asserts that the macro expansion doesn't generate a blanket `AsRef` impl forwarding // to the field type, by producing a trait implementations conflict error during // compilation, if it does. impl<T: AsRef<bool>> AsRef<bool> for Types<T> { fn as_ref(&self) -> &bool { self.0.as_ref()
}
}
#[test] fn types() { let item = Types(Helper(1, 2.0, false));
let rf: &i32 = item.as_ref();
assert!(ptr::eq(rf, item.0.as_ref()));
let rf: &f64 = item.as_ref();
assert!(ptr::eq(rf, item.0.as_ref()));
}
// Asserts that the macro expansion doesn't generate a blanket `AsRef` impl forwarding // to the field type, by producing a trait implementations conflict error during // compilation, if it does. impl<T: AsRef<bool>> AsRef<bool> for FieldTypes<T> { fn as_ref(&self) -> &bool { self.0.as_ref()
}
}
#[test] fn field_types() { let item = FieldTypes(Helper(1, 2.0, false));
let rf: &i32 = item.as_ref();
assert!(ptr::eq(rf, item.0.as_ref()));
let rf: &f64 = item.as_ref();
assert!(ptr::eq(rf, item.0.as_ref()));
}
// Asserts that the macro expansion doesn't generate a blanket `AsRef` impl forwarding to // the field type, by producing a trait implementations conflict error during compilation, // if it does. impl AsRef<bool> for Types { fn as_ref(&self) -> &bool { self.first.as_ref()
}
}
// Asserts that the macro expansion doesn't generate an `AsRef` impl for the field type, by // producing a trait implementations conflict error during compilation, if it does. impl AsRef<Helper> for Types { fn as_ref(&self) -> &Helper {
&self.first
}
}
// Asserts that the macro expansion doesn't generate a blanket `AsRef` impl forwarding to // the field type, by producing a trait implementations conflict error during compilation, // if it does. impl AsRef<bool> for TypesWithInner { fn as_ref(&self) -> &bool { self.first.as_ref()
}
}
// Asserts that the macro expansion doesn't generate a blanket `AsRef` impl forwarding to // the field type, by producing a trait implementations conflict error during compilation, // if it does. impl AsRef<bool> for TypesWithRenamedInner { fn as_ref(&self) -> &bool { self.first.as_ref()
}
}
// Asserts that the macro expansion doesn't generate a blanket `AsRef` impl forwarding to // the field type, by producing a trait implementations conflict error during compilation, // if it does. impl AsRef<bool> for FieldTypes { fn as_ref(&self) -> &bool { self.first.as_ref()
}
}
// Asserts that the macro expansion doesn't generate an `AsRef` impl for the field type, by // producing a trait implementations conflict error during compilation, if it does. impl AsRef<Helper> for FieldTypes { fn as_ref(&self) -> &Helper {
&self.first
}
}
// Asserts that the macro expansion doesn't generate a blanket `AsRef` impl forwarding to // the field type, by producing a trait implementations conflict error during compilation, // if it does. impl AsRef<bool> for FieldTypesWithInner { fn as_ref(&self) -> &bool { self.first.as_ref()
}
}
// Asserts that the macro expansion doesn't generate a blanket `AsRef` impl forwarding to // the field type, by producing a trait implementations conflict error during compilation, // if it does. impl AsRef<bool> for FieldTypesWithRenamedInner { fn as_ref(&self) -> &bool { self.first.as_ref()
}
}
// Asserts that the macro expansion doesn't generate a blanket `AsRef` impl forwarding // to the field type, by producing a trait implementations conflict error during // compilation, if it does. impl<T: AsRef<bool>> AsRef<bool> for Types<T> { fn as_ref(&self) -> &bool { self.first.as_ref()
}
}
// Asserts that the macro expansion doesn't generate a blanket `AsRef` impl forwarding // to the field type, by producing a trait implementations conflict error during // compilation, if it does. impl<T: AsRef<bool>> AsRef<bool> for FieldTypes<T> { fn as_ref(&self) -> &bool { self.first.as_ref()
}
}
// Asserts that the macro expansion doesn't generate `AsRef` impl for the skipped field, by // producing trait implementations conflict error during compilation, if it does. impl AsRef<f64> for Skip { fn as_ref(&self) -> &f64 {
&self.2
}
}
#[test] fn skip() { let item = Skip("test".to_owned(), 0, 0.0);
// Asserts that the macro expansion doesn't generate `AsRef` impl for the third field, by // producing trait implementations conflict error during compilation, if it does. impl AsRef<f64> for Field { fn as_ref(&self) -> &f64 {
&self.2
}
}
#[test] fn field() { let item = Field("test".to_owned(), 0, 0.0);
// Asserts that the macro expansion doesn't generate `AsRef` impl for the field type, by // producing trait implementations conflict error during compilation, if it does. impl AsRef<Vec<u8>> for Types { fn as_ref(&self) -> &Vec<u8> {
&self.1
}
}
#[test] fn types() { let item = Types("test".to_owned(), vec![0]);
let rf: &str = item.as_ref();
assert!(ptr::eq(rf, item.0.as_ref()));
let rf: &String = item.as_ref();
assert!(ptr::eq(rf, &item.0));
let rf: &[u8] = item.as_ref();
assert!(ptr::eq(rf, item.1.as_ref()));
}
// Asserts that the macro expansion doesn't generate `AsRef` impl for the skipped field, by // producing trait implementations conflict error during compilation, if it does. impl AsRef<f64> for Skip { fn as_ref(&self) -> &f64 {
&self.third
}
}
// Asserts that the macro expansion doesn't generate `AsRef` impl for the `third` field, by // producing trait implementations conflict error during compilation, if it does. impl AsRef<f64> for Field { fn as_ref(&self) -> &f64 {
&self.third
}
}
#[test] fn field() { let item = Field {
first: "test".to_owned(),
second: 0,
third: 0.0,
};
// Asserts that the macro expansion doesn't generate `AsRef` impl for the field type, by // producing trait implementations conflict error during compilation, if it does. impl AsRef<Vec<u8>> for Types { fn as_ref(&self) -> &Vec<u8> {
&self.second
}
}
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.29Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-08-25)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.