I have two structs with identical fields such as the following specification
struct A { a: i8, b: i8 };
struct B { a: i8, b: i8 };
and i wish to generate an Into between them. Of course I can do this with std::mem::transmute since it is an invariant that they have the identical size following they have identical fields, but i wish to do this with destructuring to ease implementation of future features. Due to the nature of the application (proc-macro) i cannot simply add pub(self) / pub(in self) since it would violate the application scope of the macro.
My current attempt uses the in scoping to try to limit it to another path but the path must be a module. I tried
struct A { pub(in B) /* pub(in self::B) */ a: i8, pub(in B) b: i8 };
struct B { pub(in A) a: i8, pub(in A) b: i8 };
This does not work since A and B are not modules. The hoped for behaviour is similar to how in C++ it would be
class A {
private:
char a;
char b;
friend class B;
}
class B {
private:
char a;
char b;
friend class A;
}
Other ideas i have coincided include creating a module including all the desired structs (this occurs inside a proc-macro attribute so this is a power i have). This would work if the specified visibility within the struct was for example pub(self) since this would be transformed into pub(super) but it would not work if the original visibility was pub(super) since this would become pub(in super::super) which is an invalid path.
Finally the last idea i had was adding an insanely named method that destructed into an ordered tuple named something like #[inline] pub(self) fn __INTERNAL_DO_NOT_USE_PUBLIC_DESTRUCTURE(self) -> (i8,i8) and then destructing this. This is undesirable.
TL;DR: how to I expose fields to 'friend' structs without exposing them to the rest of the module.