#[allow(dead_code)] #[allow(non_camel_case_types)] #[repr(C)] pub struct Partial { a: Module::F_a, } impl PartialBorrow for Struct { type All_No = Partial; type All_Const = Partial; type All_Mut = Partial; type Fields = Module::Fields; const FIELDS: Self::Fields = Module::FIELDS; } #[allow(non_camel_case_types)] impl Deref for Module::F_a where P: IsRef, { type Target = T; fn deref(&self) -> &T where T: Sized, { unsafe { let p: *const Self = self; let p: *const Struct = p as usize as _; let offset = offset_of!(Struct, a); let p: *const u8 = p as _; let p = p.add(offset); let p: *const T = p as _; let p: &T = p.as_ref().unwrap(); p } } } #[allow(non_camel_case_types)] impl DerefMut for Module::F_a where P: IsMut, { fn deref_mut(&mut self) -> &mut T where T: Sized, { unsafe { let p: *mut Self = self; let p: *mut Struct = p as usize as _; let offset = offset_of!(Struct, a); let p: *mut u8 = p as _; let p = p.add(offset); let p: *mut T = p as _; let p: &mut T = p.as_mut().unwrap(); p } } } #[allow(non_camel_case_types)] impl Debug for Module::F_a where T: Debug, P: IsRefOrNot, { fn fmt<'r>(&'r self, f: &mut Formatter) -> fmt::Result { if let Some(Const) =

::REF { let downgraded = unsafe { transmute::< &'r Module::F_a, &'r Module::F_a, >(self) }; Debug::fmt(&**downgraded, f) } else { Formatter::write_str(f, "_") } } } #[allow(non_camel_case_types)] impl Adjust for Partial { type Adjusted = Partial; } #[allow(non_camel_case_types)] impl AsRef> for Partial where Ra: IsDowngradeFrom, { fn as_ref(&self) -> &Partial { Downgrade::downgrade(self) } } #[allow(non_camel_case_types)] impl AsMut> for Partial where Ra: IsDowngradeFrom, { fn as_mut(&mut self) -> &mut Partial { Downgrade::downgrade_mut(self) } } #[allow(non_camel_case_types)] impl Downgrade> for Partial where Ra: IsDowngradeFrom, { fn downgrade(input: &Self) -> &Partial { unsafe { let input = input as *const _; (input as *const Partial).as_ref().unwrap() } } fn downgrade_mut(input: &mut Self) -> &mut Partial { unsafe { let input = input as *mut _; (input as *mut Partial).as_mut().unwrap() } } } #[allow(non_camel_case_types)] impl SplitOff> for Partial where Ra: IsDowngradeFrom, { type Remaining = Partial<>::Remaining>; fn split_off<'r>( input: &'r Partial, ) -> (&'r Partial, &'r Self::Remaining) { unsafe { let input = input as *const _; ( (input as *const Partial).as_ref().unwrap(), (input as *const Self::Remaining).as_ref().unwrap(), ) } } fn split_off_mut<'r>( input: &'r mut Partial, ) -> (&'r mut Partial, &'r mut Self::Remaining) { unsafe { let input = input as *mut _; ( (input as *mut Partial).as_mut().unwrap(), (input as *mut Self::Remaining).as_mut().unwrap(), ) } } } #[allow(non_camel_case_types)] impl<'r, Ra, Sa, Pa> From<&'r Partial> for (&'r Partial, &'r Partial) where Pa: CanSplitInto, { fn from(input: &'r Partial) -> Self { SplitInto::split_into(input) } } #[allow(non_camel_case_types)] impl<'r, Ra, Sa, Pa> From<&'r mut Partial> for (&'r mut Partial, &'r mut Partial) where Pa: CanSplitInto, { fn from(input: &'r mut Partial) -> Self { SplitInto::split_into_mut(input) } } #[allow(non_camel_case_types)] impl SplitInto, Partial> for Partial where Pa: CanSplitInto, { fn split_into<'r>( input: &'r Partial, ) -> (&'r Partial, &'r Partial) { unsafe { let input = input as *const _; ( (input as *const Partial).as_ref().unwrap(), (input as *const Partial).as_ref().unwrap(), ) } } fn split_into_mut<'r>( input: &'r mut Partial, ) -> (&'r mut Partial, &'r mut Partial) { unsafe { let input = input as *mut _; ( (input as *mut Partial).as_mut().unwrap(), (input as *mut Partial).as_mut().unwrap(), ) } } } #[allow(non_camel_case_types)] impl AsRef> for Struct where Ra: IsDowngradeFrom, { fn as_ref(&self) -> &Partial { Downgrade::downgrade(self) } } #[allow(non_camel_case_types)] impl AsMut> for Struct where Ra: IsDowngradeFrom, { fn as_mut(&mut self) -> &mut Partial { Downgrade::downgrade_mut(self) } } #[allow(non_camel_case_types)] impl Downgrade> for Struct where Ra: IsDowngradeFrom, { fn downgrade(input: &Self) -> &Partial { unsafe { let input = input as *const _ as usize; (input as *const Partial).as_ref().unwrap() } } fn downgrade_mut(input: &mut Self) -> &mut Partial { unsafe { let input = input as *mut _ as usize; (input as *mut Partial).as_mut().unwrap() } } } #[allow(non_camel_case_types)] impl SplitOff> for Struct where Ra: IsDowngradeFrom, { type Remaining = Partial<>::Remaining>; fn split_off<'r>( input: &'r Struct, ) -> (&'r Partial, &'r Self::Remaining) { unsafe { let input = input as *const _ as usize; ( (input as *const Partial).as_ref().unwrap(), (input as *const Self::Remaining).as_ref().unwrap(), ) } } fn split_off_mut<'r>( input: &'r mut Struct, ) -> (&'r mut Partial, &'r mut Self::Remaining) { unsafe { let input = input as *mut _ as usize; ( (input as *mut Partial).as_mut().unwrap(), (input as *mut Self::Remaining).as_mut().unwrap(), ) } } } #[allow(non_camel_case_types)] impl<'r, Ra, Sa> From<&'r Struct> for (&'r Partial, &'r Partial) where Mut: CanSplitInto, { fn from(input: &'r Struct) -> Self { SplitInto::split_into(input) } } #[allow(non_camel_case_types)] impl<'r, Ra, Sa> From<&'r mut Struct> for (&'r mut Partial, &'r mut Partial) where Mut: CanSplitInto, { fn from(input: &'r mut Struct) -> Self { SplitInto::split_into_mut(input) } } #[allow(non_camel_case_types)] impl SplitInto, Partial> for Struct where Mut: CanSplitInto, { fn split_into<'r>(input: &'r Struct) -> (&'r Partial, &'r Partial) { unsafe { let input = input as *const _ as usize; ( (input as *const Partial).as_ref().unwrap(), (input as *const Partial).as_ref().unwrap(), ) } } fn split_into_mut<'r>( input: &'r mut Struct, ) -> (&'r mut Partial, &'r mut Partial) { unsafe { let input = input as *mut _ as usize; ( (input as *mut Partial).as_mut().unwrap(), (input as *mut Partial).as_mut().unwrap(), ) } } } #[allow(non_camel_case_types)] impl Deref for Partial where Pa: IsRef, { type Target = Struct; fn deref(&self) -> &Self::Target { unsafe { let p: *const Self = self as _; let p: *const Self::Target = p as usize as _; let p = p.as_ref().unwrap(); p } } } #[allow(non_camel_case_types)] impl Debug for Partial where Module::F_a: Debug, { fn fmt(&self, f: &mut Formatter) -> fmt::Result { let mut fields = Formatter::debug_struct(f, "Partial"); fmt::DebugStruct::field(&mut fields, "a", &self.a); fields.finish() } } #[allow(dead_code)] #[allow(non_camel_case_types)] #[allow(non_snake_case)] pub mod Module { use super::*; #[repr(C)] pub struct F_a { p: P, t: PhantomData, s: PhantomData<*const S>, } pub struct Fields { pub a: usize, } pub const FIELDS: Fields = Fields { a: 0usize }; }