use core::borrow::{Borrow, BorrowMut};
use core::fmt;
use core::marker::PhantomData;
use core::ops::{Deref, DerefMut};
use wrapper_lite::__wrapper;
const fn assert_debug<T>()
where
T: fmt::Debug,
{
}
const fn assert_display<T>()
where
T: fmt::Display,
{
}
const fn assert_as_ref<T, U>()
where
T: AsRef<U>,
U: ?Sized,
{
}
const fn assert_as_mut<T, U>()
where
T: AsMut<U>,
U: ?Sized,
{
}
const fn assert_borrow<T, U>()
where
T: Borrow<U>,
U: ?Sized,
{
}
const fn assert_borrow_mut<T, U>()
where
T: BorrowMut<U>,
U: ?Sized,
{
}
const fn assert_deref<T, U>()
where
T: Deref<Target = U>,
U: ?Sized,
{
}
const fn assert_deref_mut<T, U>()
where
T: DerefMut<Target = U>,
U: ?Sized,
{
}
const fn assert_from<T, U>()
where
T: From<U>,
{
}
const _: () = {
__wrapper!(
#[allow(dead_code)]
#[bound('c: 'a + 'b)]
#[wrapper(Debug)]
#[wrapper(Display)]
#[wrapper(AsRef)]
#[wrapper(AsMut)]
#[wrapper(BorrowMut)]
#[wrapper(DerefMut)]
#[wrapper(From)]
#[repr(align(cache))]
#[bound('b: 'a)]
#[bound(M: Default)]
#[bound(N: ?Sized)]
#[bound(O: ?Sized + fmt::Debug)]
#[derive(Clone)]
pub struct Foobar<'a, 'b, 'c, 'd: 'a, M, N, O = [u8]>(
pub(crate) (M, &'a N, &'a O, PhantomData<&'b &'c &'d ()>),
);
);
impl<'a, 'b, 'c, 'd: 'a, M, N, O> Foobar<'a, 'b, 'c, 'd, M, N, O>
where
O: ?Sized + fmt::Debug,
N: ?Sized,
M: Default,
'b: 'a,
'c: 'a + 'b,
{
}
__wrapper!(
#[allow(dead_code)]
#[bound('c: 'a + 'b)]
#[wrapper(Debug)]
#[wrapper(Display)]
#[wrapper(AsRef)]
#[wrapper(AsMut)]
#[wrapper(BorrowMut)]
#[wrapper(DerefMut)]
#[wrapper(From)]
#[repr(align(cache))]
#[bound('b: 'a)]
#[bound(M: Default)]
#[bound(N: ?Sized)]
#[bound(O: ?Sized + fmt::Debug)]
#[derive(Clone)]
pub struct Barfoo<'a, 'b, 'c, 'd: 'a, M, N, O = [u8]> {
pub(crate) the_inner_name_doesnt_matter: (M, &'a N, &'a O, PhantomData<&'b &'c &'d ()>),
}
);
impl<'a, 'b, 'c, 'd: 'a, M, N, O> Barfoo<'a, 'b, 'c, 'd, M, N, O>
where
O: ?Sized + fmt::Debug,
N: ?Sized,
M: Default,
'b: 'a,
'c: 'a + 'b,
{
#[allow(dead_code)]
fn test(&self) {
let _ = &self.the_inner_name_doesnt_matter;
}
}
__wrapper!(
#[allow(dead_code)]
#[bound('c: 'a + 'b)]
#[wrapper(Debug)]
#[wrapper(Display)]
#[wrapper(AsRef)]
#[wrapper(AsMut)]
#[wrapper(BorrowMut)]
#[wrapper(DerefMut)]
#[bound('b: 'a)]
#[bound(M: Default)]
#[bound(N: ?Sized)]
#[bound(O: ?Sized + fmt::Debug)]
#[derive(Clone)]
#[repr(align(cache))]
pub struct BarfooWithOtherFields<'a, 'b, 'c, 'd: 'a, M, N, O = [u8]> {
pub(crate) the_inner_name_doesnt_matter: (M, &'a N, &'a O, PhantomData<&'b &'c &'d ()>),
other_field: usize,
}
);
impl<'a, 'b, 'c, 'd: 'a, M, N, O> BarfooWithOtherFields<'a, 'b, 'c, 'd, M, N, O>
where
O: ?Sized + fmt::Debug,
N: ?Sized,
M: Default,
'b: 'a,
'c: 'a + 'b,
{
#[allow(dead_code)]
fn test(&self) {
let _ = &self.the_inner_name_doesnt_matter;
let _ = &self.other_field;
}
}
__wrapper!(
#[allow(dead_code)]
#[bound('c: 'a + 'b)]
#[wrapper(Debug)]
#[wrapper(Display)]
#[wrapper(AsRef)]
#[wrapper(AsMut)]
#[wrapper(BorrowMut)]
#[wrapper(DerefMut)]
#[wrapper(From)]
#[bound('b: 'a)]
#[bound(M: Default)]
#[bound(N: ?Sized)]
#[bound(O: ?Sized + fmt::Debug)]
#[derive(Clone)]
#[repr(align(cache))]
pub struct BarfooWithOtherFieldsWithDefault<'a, 'b, 'c, 'd: 'a, M, N, O = [u8]> {
pub(crate) the_inner_name_doesnt_matter: (M, &'a N, &'a O, PhantomData<&'b &'c &'d ()>),
#[default(0)]
other_field: usize,
}
);
impl<'a, 'b, 'c, 'd: 'a, M, N, O> BarfooWithOtherFieldsWithDefault<'a, 'b, 'c, 'd, M, N, O>
where
O: ?Sized + fmt::Debug,
N: ?Sized,
M: Default,
'b: 'a,
'c: 'a + 'b,
{
#[allow(dead_code)]
fn test(&self) {
let _ = &self.the_inner_name_doesnt_matter;
let _ = &self.other_field;
let _ = Self::from_inner;
}
}
};
#[allow(unexpected_cfgs)]
const _: () = {
__wrapper!(
#[cfg(feature = "_test_cfg")]
#[allow(dead_code)]
#[bound('c: 'a + 'b)]
#[wrapper(Debug)]
#[wrapper(Display)]
#[wrapper(AsRef)]
#[wrapper(AsMut)]
#[wrapper(BorrowMut)]
#[wrapper(DerefMut)]
#[wrapper(From)]
#[repr(align(cache))]
#[bound('b: 'a)]
#[bound(M: Default)]
#[bound(N: ?Sized)]
#[bound(O: ?Sized + fmt::Debug)]
#[derive(Clone)]
pub struct Foobar<'a, 'b, 'c, 'd: 'a, M, N, O = [u8]>(
pub(crate) (M, &'a N, &'a O, PhantomData<&'b &'c &'d ()>),
);
);
#[cfg(feature = "_test_cfg")]
impl<'a, 'b, 'c, 'd: 'a, M, N, O> Foobar<'a, 'b, 'c, 'd, M, N, O>
where
O: ?Sized + fmt::Debug,
N: ?Sized,
M: Default,
'b: 'a,
'c: 'a + 'b,
{
}
__wrapper!(
#[cfg(feature = "_test_cfg")]
#[allow(dead_code)]
#[bound('c: 'a + 'b)]
#[wrapper(Debug)]
#[wrapper(Display)]
#[wrapper(AsRef)]
#[wrapper(AsMut)]
#[wrapper(BorrowMut)]
#[wrapper(DerefMut)]
#[wrapper(From)]
#[repr(align(cache))]
#[bound('b: 'a)]
#[bound(M: Default)]
#[bound(N: ?Sized)]
#[bound(O: ?Sized + fmt::Debug)]
#[derive(Clone)]
pub struct Barfoo<'a, 'b, 'c, 'd: 'a, M, N, O = [u8]> {
pub(crate) the_inner_name_doesnt_matter: (M, &'a N, &'a O, PhantomData<&'b &'c &'d ()>),
}
);
#[cfg(feature = "_test_cfg")]
impl<'a, 'b, 'c, 'd: 'a, M, N, O> Barfoo<'a, 'b, 'c, 'd, M, N, O>
where
O: ?Sized + fmt::Debug,
N: ?Sized,
M: Default,
'b: 'a,
'c: 'a + 'b,
{
#[allow(dead_code)]
fn test(&self) {
let _ = &self.the_inner_name_doesnt_matter;
}
}
__wrapper!(
#[cfg(feature = "_test_cfg")]
#[allow(dead_code)]
#[bound('c: 'a + 'b)]
#[wrapper(Debug)]
#[wrapper(Display)]
#[wrapper(AsRef)]
#[wrapper(AsMut)]
#[wrapper(BorrowMut)]
#[wrapper(DerefMut)]
#[bound('b: 'a)]
#[bound(M: Default)]
#[bound(N: ?Sized)]
#[bound(O: ?Sized + fmt::Debug)]
#[derive(Clone)]
#[repr(align(cache))]
pub struct BarfooWithOtherFields<'a, 'b, 'c, 'd: 'a, M, N, O = [u8]> {
pub(crate) the_inner_name_doesnt_matter: (M, &'a N, &'a O, PhantomData<&'b &'c &'d ()>),
other_field: usize,
}
);
#[cfg(feature = "_test_cfg")]
impl<'a, 'b, 'c, 'd: 'a, M, N, O> BarfooWithOtherFields<'a, 'b, 'c, 'd, M, N, O>
where
O: ?Sized + fmt::Debug,
N: ?Sized,
M: Default,
'b: 'a,
'c: 'a + 'b,
{
#[allow(dead_code)]
fn test(&self) {
let _ = &self.the_inner_name_doesnt_matter;
let _ = &self.other_field;
}
}
__wrapper!(
#[cfg(feature = "_test_cfg")]
#[allow(dead_code)]
#[bound('c: 'a + 'b)]
#[wrapper(Debug)]
#[wrapper(Display)]
#[wrapper(AsRef)]
#[wrapper(AsMut)]
#[wrapper(BorrowMut)]
#[wrapper(DerefMut)]
#[wrapper(From)]
#[bound('b: 'a)]
#[bound(M: Default)]
#[bound(N: ?Sized)]
#[bound(O: ?Sized + fmt::Debug)]
#[derive(Clone)]
#[repr(align(cache))]
pub struct BarfooWithOtherFieldsWithDefault<'a, 'b, 'c, 'd: 'a, M, N, O = [u8]> {
pub(crate) the_inner_name_doesnt_matter: (M, &'a N, &'a O, PhantomData<&'b &'c &'d ()>),
#[default(0)]
other_field: usize,
}
);
#[cfg(feature = "_test_cfg")]
impl<'a, 'b, 'c, 'd: 'a, M, N, O> BarfooWithOtherFieldsWithDefault<'a, 'b, 'c, 'd, M, N, O>
where
O: ?Sized + fmt::Debug,
N: ?Sized,
M: Default,
'b: 'a,
'c: 'a + 'b,
{
#[allow(dead_code)]
fn test(&self) {
let _ = &self.the_inner_name_doesnt_matter;
let _ = &self.other_field;
let _ = Self::from_inner;
}
}
};
#[test]
fn test_debug() {
#[derive(Debug)]
struct Case;
{
__wrapper!(
#[wrapper(Debug)]
struct Wrapper(Case);
);
assert_debug::<Wrapper>();
assert_eq!(format!("{:?}", Wrapper { inner: Case }), "Case");
}
{
__wrapper!(
#[wrapper(Debug)]
struct Wrapper {
inner: Case,
}
);
assert_debug::<Wrapper>();
assert_eq!(format!("{:?}", Wrapper { inner: Case }), "Case");
}
}
#[test]
fn test_debug_name() {
#[derive(Debug)]
struct Case;
{
__wrapper!(
#[wrapper(DebugName)]
struct Wrapper(Case);
);
assert_debug::<Wrapper>();
assert_eq!(format!("{:?}", Wrapper { inner: Case }), "Wrapper");
}
{
__wrapper!(
#[wrapper(DebugName)]
struct Wrapper {
inner: Case,
}
);
assert_debug::<Wrapper>();
assert_eq!(format!("{:?}", Wrapper { inner: Case }), "Wrapper");
}
}
#[test]
fn test_display() {
#[derive(Debug)]
struct Case;
impl fmt::Display for Case {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "cASE")
}
}
{
__wrapper!(
#[wrapper(Display)]
struct Wrapper(Case);
);
assert_display::<Wrapper>();
assert_eq!(format!("{}", Wrapper { inner: Case }), "cASE");
}
{
__wrapper!(
#[wrapper(Display)]
struct Wrapper {
inner: Case,
}
);
assert_display::<Wrapper>();
assert_eq!(format!("{}", Wrapper { inner: Case }), "cASE");
}
}
const _: () = {
const _: () = {
__wrapper!(
#[wrapper(AsRef)]
struct Wrapper(u8);
);
assert_as_ref::<Wrapper, u8>();
};
const _: () = {
__wrapper!(
#[wrapper(AsRef)]
struct Wrapper {
inner: u8,
}
);
assert_as_ref::<Wrapper, u8>();
};
const _: () = {
__wrapper!(
#[wrapper(AsRef<[u8]>)]
struct Wrapper(Vec<u8>);
);
assert_as_ref::<Wrapper, [u8]>();
};
const _: () = {
__wrapper!(
#[wrapper(AsRef<[u8]>)]
struct Wrapper {
inner: Vec<u8>,
}
);
assert_as_ref::<Wrapper, [u8]>();
};
const _: () = {
__wrapper!(
#[wrapper(AsRef)]
#[wrapper(AsRef<[u8]>)]
struct Wrapper([u8; 168]);
);
assert_as_ref::<Wrapper, [u8; 168]>();
assert_as_ref::<Wrapper, [u8]>();
};
const _: () = {
__wrapper!(
#[wrapper(AsRef)]
#[wrapper(AsRef<[u8]>)]
struct Wrapper {
inner: [u8; 168],
}
);
assert_as_ref::<Wrapper, [u8; 168]>();
assert_as_ref::<Wrapper, [u8]>();
};
};
const _: () = {
const _: () = {
__wrapper!(
#[wrapper(AsMut)]
struct Wrapper(u8);
);
assert_as_mut::<Wrapper, u8>();
};
const _: () = {
__wrapper!(
#[wrapper(AsMut)]
struct Wrapper {
inner: u8,
}
);
assert_as_mut::<Wrapper, u8>();
};
const _: () = {
__wrapper!(
#[wrapper(AsMut<[u8]>)]
struct Wrapper(Vec<u8>);
);
assert_as_mut::<Wrapper, [u8]>();
};
const _: () = {
__wrapper!(
#[wrapper(AsMut<[u8]>)]
struct Wrapper {
inner: Vec<u8>,
}
);
assert_as_mut::<Wrapper, [u8]>();
};
const _: () = {
__wrapper!(
#[wrapper(AsMut)]
#[wrapper(AsMut<[u8]>)]
struct Wrapper([u8; 168]);
);
assert_as_mut::<Wrapper, [u8; 168]>();
assert_as_mut::<Wrapper, [u8]>();
};
const _: () = {
__wrapper!(
#[wrapper(AsMut)]
#[wrapper(AsMut<[u8]>)]
struct Wrapper {
inner: [u8; 168],
}
);
assert_as_mut::<Wrapper, [u8; 168]>();
assert_as_mut::<Wrapper, [u8]>();
};
const _: () = {
__wrapper!(
#[wrapper([const] AsMut)]
struct Wrapper(u8);
);
assert_as_mut::<Wrapper, u8>();
};
const _: () = {
__wrapper!(
#[wrapper([const] AsMut)]
struct Wrapper {
inner: u8,
}
);
assert_as_mut::<Wrapper, u8>();
};
const _: () = {
__wrapper!(
#[wrapper(AsMut<[u8]>)]
struct Wrapper(Vec<u8>);
);
assert_as_mut::<Wrapper, [u8]>();
};
const _: () = {
__wrapper!(
#[wrapper(AsMut<[u8]>)]
struct Wrapper {
inner: Vec<u8>,
}
);
assert_as_mut::<Wrapper, [u8]>();
};
const _: () = {
__wrapper!(
#[wrapper([const] AsMut)]
#[wrapper(AsMut<[u8]>)]
struct Wrapper([u8; 168]);
);
assert_as_mut::<Wrapper, [u8; 168]>();
assert_as_mut::<Wrapper, [u8]>();
};
const _: () = {
__wrapper!(
#[wrapper([const] AsMut)]
#[wrapper(AsMut<[u8]>)]
struct Wrapper {
inner: [u8; 168],
}
);
assert_as_mut::<Wrapper, [u8; 168]>();
assert_as_mut::<Wrapper, [u8]>();
};
};
const _: () = {
const _: () = {
__wrapper!(
#[wrapper(Borrow)]
struct Wrapper(u8);
);
assert_borrow::<Wrapper, u8>();
};
const _: () = {
__wrapper!(
#[wrapper(Borrow)]
struct Wrapper {
inner: u8,
}
);
assert_borrow::<Wrapper, u8>();
};
const _: () = {
__wrapper!(
#[wrapper(Borrow<[u8]>)]
struct Wrapper(Vec<u8>);
);
assert_borrow::<Wrapper, [u8]>();
};
const _: () = {
__wrapper!(
#[wrapper(Borrow<[u8]>)]
struct Wrapper {
inner: Vec<u8>,
}
);
assert_borrow::<Wrapper, [u8]>();
};
const _: () = {
__wrapper!(
#[wrapper(Borrow)]
#[wrapper(Borrow<[u8]>)]
struct Wrapper([u8; 168]);
);
assert_borrow::<Wrapper, [u8; 168]>();
assert_borrow::<Wrapper, [u8]>();
};
const _: () = {
__wrapper!(
#[wrapper(Borrow)]
#[wrapper(Borrow<[u8]>)]
struct Wrapper {
inner: [u8; 168],
}
);
assert_borrow::<Wrapper, [u8; 168]>();
assert_borrow::<Wrapper, [u8]>();
};
};
const _: () = {
const _: () = {
__wrapper!(
#[wrapper(BorrowMut)]
struct Wrapper(u8);
);
assert_borrow::<Wrapper, u8>();
assert_borrow_mut::<Wrapper, u8>();
};
const _: () = {
__wrapper!(
#[wrapper(BorrowMut)]
struct Wrapper {
inner: u8,
}
);
assert_borrow::<Wrapper, u8>();
assert_borrow_mut::<Wrapper, u8>();
};
const _: () = {
__wrapper!(
#[wrapper(BorrowMut<[u8]>)]
struct Wrapper(Vec<u8>);
);
assert_borrow::<Wrapper, [u8]>();
assert_borrow_mut::<Wrapper, [u8]>();
};
const _: () = {
__wrapper!(
#[wrapper(BorrowMut<[u8]>)]
struct Wrapper {
inner: Vec<u8>,
}
);
assert_borrow::<Wrapper, [u8]>();
assert_borrow_mut::<Wrapper, [u8]>();
};
};
const _: () = {
const _: () = {
__wrapper!(
#[wrapper(Deref)]
struct Wrapper(u8);
);
assert_deref::<Wrapper, u8>();
};
const _: () = {
__wrapper!(
#[wrapper(Deref)]
struct Wrapper {
inner: u8,
}
);
assert_deref::<Wrapper, u8>();
};
const _: () = {
__wrapper!(
#[wrapper(Deref<[u8]>)]
struct Wrapper(Vec<u8>);
);
assert_deref::<Wrapper, [u8]>();
};
const _: () = {
__wrapper!(
#[wrapper(Deref<[u8]>)]
struct Wrapper {
inner: Vec<u8>,
}
);
assert_deref::<Wrapper, [u8]>();
};
};
const _: () = {
const _: () = {
__wrapper!(
#[wrapper(DerefMut)]
struct Wrapper(u8);
);
assert_deref::<Wrapper, u8>();
assert_deref_mut::<Wrapper, u8>();
};
const _: () = {
__wrapper!(
#[wrapper(DerefMut)]
struct Wrapper {
inner: u8,
}
);
assert_deref::<Wrapper, u8>();
assert_deref_mut::<Wrapper, u8>();
};
const _: () = {
__wrapper!(
#[wrapper(DerefMut<[u8]>)]
struct Wrapper(Vec<u8>);
);
assert_deref::<Wrapper, [u8]>();
assert_deref_mut::<Wrapper, [u8]>();
};
const _: () = {
__wrapper!(
#[wrapper(DerefMut<[u8]>)]
struct Wrapper {
inner: Vec<u8>,
}
);
assert_deref::<Wrapper, [u8]>();
assert_deref_mut::<Wrapper, [u8]>();
};
};
const _: () = {
const _: () = {
__wrapper!(
#[wrapper(From)]
struct Wrapper(u8);
);
assert_from::<Wrapper, u8>();
};
const _: () = {
__wrapper!(
#[wrapper(From)]
struct Wrapper {
inner: u8,
}
);
assert_from::<Wrapper, u8>();
};
};