repr_offset/get_field_offset.rs
1//! Trait for getting the `FieldOffset` of a field, and related items.
2//!
3//! One would implement the [`ImplsGetFieldOffset`] and [`GetFieldOffset`] traits,
4//! and use [`GetPubFieldOffset`] as a bound.
5//!
6//! [`ImplsGetFieldOffset`]: ./trait.ImplsGetFieldOffset.html
7//! [`GetFieldOffset`]: ./trait.GetFieldOffset.html
8//! [`GetPubFieldOffset`]: ./trait.GetPubFieldOffset.html
9
10use crate::{privacy::IsPublic, FieldOffset};
11
12use core::marker::PhantomData;
13
14mod tuple_impls;
15
16//////////////////////////////////////////////////////////////////////////////////
17
18/// Marker trait for types that implement `GetFieldOffset`.
19///
20/// This trait is required for the `GetFieldOffset` impls that
21/// get the [`FieldOffset`] of nested fields.
22///
23///
24/// [`FieldOffset`]: ../struct.FieldOffset.html
25///
26/// This is only required as a workaround to lower the time that `cargo doc` takes to run.
27pub unsafe trait ImplsGetFieldOffset: Sized {}
28
29//////////////////////////////////////////////////////////////////////////////////
30
31/// Hack use by `repr_offset` to implement `GetFieldOffset<(N0, N1, ...)>`
32/// for all types without blowing up the time that `cargo doc` takes to run.
33pub struct ImplGetNestedFieldOffset<T>(T);
34
35//////////////////////////////////////////////////////////////////////////////////
36
37/// For getting the offset of a field given its name.
38///
39/// This trait exists to make it possible for the
40/// [`OFF!`], [`off`], [`PUB_OFF!`], and [`pub_off`] macros
41/// to get the [`FieldOffset`] of a field.
42///
43/// This trait is by default implemented by the [`unsafe_struct_field_offsets`] macro,
44/// and [`ReprOffset`] derive macro.
45///
46/// [`unsafe_struct_field_offsets`]: ../macro.unsafe_struct_field_offsets.html
47/// [`ReprOffset`]: ../derive.ReprOffset.html
48///
49/// # Safety
50///
51/// ### Non-nested fields
52///
53/// Implementors must ensure that for any given impl of `GetFieldOffset<TS!(<field_name>)>`
54/// for a type there is a `<field_name>` field stored inline in the type,
55/// accessible through `.<field_name>`.
56///
57/// Implementors must ensure that the
58/// [`OFFSET_WITH_VIS`](#associatedconstant.OFFSET_WITH_VIS)
59/// associated constant contains the [`FieldOffset`] for the `<field_name>` field,
60/// with the correct offset(in bytes), field type, and alignment type parameter.
61///
62/// Implementors must ensure that there is the only one impl of
63/// `GetFieldOffset` for that type through
64/// which one can get the [`FieldOffset`] for the `<field_name>` field,
65///
66/// `<field_name>` is used here to refer to any one field (eg: a field named `foo`),
67/// all mentions of that field in this section refer to the same field.
68///
69///
70/// # SemVer
71///
72/// Impls of this trait where the `Privacy` associated type is `Private`
73/// can change or be removed in semver compatible versions,
74///
75/// Prefer using the [`GetPubFieldOffset`] trait alias for bounds instead,
76/// since that is for public fields.
77///
78/// # Type Parameter
79///
80/// The `FN` type parameter is the path to the field that this gets the offset for, it can be:
81///
82/// - A [`tstr::TStr`]: representing a single field, eg: (`tstr::TS!(foo)`).
83///
84/// - A tuple of [`tstr::TStr`]s: representing a nested field, eg: (`tstr::TS!(foo,bar,baz)`).
85///
86/// # Example
87///
88/// ### Manual Implementation
89///
90/// This example demonstrates how you can implement `GetFieldOffset` manually.
91///
92/// ```rust
93/// use repr_offset::{
94/// alignment::{Aligned, Unaligned},
95/// get_field_offset::{GetFieldOffset, FieldOffsetWithVis as FOWithVis},
96/// privacy::{IsPublic, IsPrivate},
97/// tstr::TS,
98/// off, pub_off,
99/// FieldOffset, ROExtAcc, ROExtOps,
100/// };
101///
102/// #[repr(C, packed)]
103/// struct Foo {
104/// wheel_count: u8,
105/// pub(crate) seat_size: u128,
106/// pub is_automatic: bool,
107/// }
108///
109/// let foo = Foo {
110/// wheel_count: 3,
111/// seat_size: 5,
112/// is_automatic: false,
113/// };
114///
115/// // We can get a reference because the field is aligned.
116/// assert_eq!(foo.f_get(off!(wheel_count)), &3);
117///
118/// // The seat_size field is unaligned inside of Foo, so we can't get a reference.
119/// assert_eq!(foo.f_get_copy(off!(seat_size)), 5);
120///
121/// // We can get a reference because the field is aligned.
122/// //
123/// // Also, because the field is public, you can use `pub_off` to get its FieldOffset.
124/// assert_eq!(foo.f_get(pub_off!(is_automatic)), &false);
125///
126///
127/// unsafe impl GetFieldOffset<TS!(wheel_count)> for Foo {
128/// type Type = u8;
129/// type Alignment = Aligned;
130/// type Privacy = IsPrivate;
131///
132/// const OFFSET_WITH_VIS: FOWithVis<Self, IsPrivate, TS!(wheel_count), u8, Aligned> = unsafe {
133/// FOWithVis::new(0)
134/// };
135/// }
136///
137/// unsafe impl GetFieldOffset<TS!(seat_size)> for Foo {
138/// type Type = u128;
139/// type Alignment = Unaligned;
140/// type Privacy = IsPrivate;
141///
142/// const OFFSET_WITH_VIS: FOWithVis<Self, IsPrivate, TS!(seat_size), u128, Unaligned> =
143/// unsafe{
144/// <Self as GetFieldOffset<TS!(wheel_count)>>::OFFSET_WITH_VIS
145/// .private_field_offset()
146/// .next_field_offset()
147/// .with_vis()
148/// };
149/// }
150///
151/// unsafe impl GetFieldOffset<TS!(is_automatic)> for Foo {
152/// type Type = bool;
153/// type Alignment = Aligned;
154/// type Privacy = IsPublic;
155///
156/// const OFFSET_WITH_VIS: FOWithVis<Self, IsPublic, TS!(is_automatic), bool, Aligned> =
157/// unsafe{
158/// <Self as GetFieldOffset<TS!(seat_size)>>::OFFSET_WITH_VIS
159/// .private_field_offset()
160/// .next_field_offset()
161/// .with_vis()
162/// };
163/// }
164///
165/// ```
166///
167/// [`FieldOffset`]: ../struct.FieldOffset.html
168///
169/// [`GetPubFieldOffset`]: ./trait.GetPubFieldOffset.html
170///
171/// [`OFF!`]: ../macro.OFF.html
172/// [`off`]: ../macro.off.html
173/// [`PUB_OFF!`]: ../macro.PUB_OFF.html
174/// [`pub_off`]: ../macro.pub_off.html
175///
176///
177///
178pub unsafe trait GetFieldOffset<FN>: Sized {
179 /// The type of the field.
180 type Type;
181 /// Whether the field is:
182 ///
183 /// - [`Aligned`]: `Self` has an alignment greater than or equal to the field type,
184 /// usually when `Self` has one of the
185 /// `#[repr(C)]`/`#[repr(C, align(...))]`/`#[repr(transparent)]` representations.
186 ///
187 /// - [`Unaligned`]: `Self` has an alignment smaller than the field type,
188 /// usually when `Self` has the `#[repr(C, packed)]` representation.
189 ///
190 /// [`Aligned`]: ../alignment/struct.Aligned.html
191 /// [`Unaligned`]: ../alignment/struct.Unaligned.html
192 type Alignment;
193
194 /// Whether the field is private or not, either:
195 ///
196 /// - [`IsPublic`]: When the field is `pub`.
197 ///
198 /// - [`IsPrivate`]: When the field has the default (private) visibility,
199 /// or has a visibility smaller or equal to `pub(crate)`.
200 ///
201 /// [`IsPublic`]: ../privacy/struct.IsPublic.html
202 /// [`IsPrivate`]: ../privacy/struct.IsPrivate.html
203 type Privacy;
204
205 /// The offset of the field.
206 const OFFSET_WITH_VIS: FieldOffsetWithVis<
207 Self,
208 Self::Privacy,
209 FN,
210 Self::Type,
211 Self::Alignment,
212 >;
213}
214
215//////////////////////////////////////////////////////////////////////////////////
216
217/// An alias of the [`GetFieldOffset`] trait for public fields.
218///
219/// # Example
220///
221/// Defining a generic method for all types that have `a`, and `c` fields
222///
223/// ```rust
224/// use repr_offset::{
225/// for_examples::ReprC,
226/// get_field_offset::FieldType,
227/// privacy::{IsPublic, IsPrivate},
228/// tstr::TS,
229/// pub_off,
230/// Aligned, GetPubFieldOffset, ROExtAcc,
231/// };
232///
233/// use std::fmt::Debug;
234///
235/// print_a_c(&ReprC{a: 10, b: 20, c: 30, d: 40 });
236///
237/// fn print_a_c<T>(this: &T)
238/// where
239/// T: GetPubFieldOffset<TS!(a), Alignment = Aligned>,
240/// T: GetPubFieldOffset<TS!(b), Alignment = Aligned>,
241/// FieldType<T, TS!(a)>: Debug,
242/// FieldType<T, TS!(b)>: Debug,
243/// {
244/// println!("{:?}", this.f_get(pub_off!(a)));
245/// println!("{:?}", this.f_get(pub_off!(b)));
246///
247/// # use repr_offset::get_field_offset::FieldAlignment;
248/// # let _: FieldAlignment<T, TS!(a)> = Aligned;
249/// # let _: FieldAlignment<T, TS!(b)> = Aligned;
250/// }
251///
252/// ```
253///
254/// [`GetFieldOffset`]: ./trait.GetFieldOffset.html
255pub trait GetPubFieldOffset<FN>: GetFieldOffset<FN, Privacy = IsPublic> {
256 /// The offset of the field.
257 const OFFSET: FieldOffset<Self, Self::Type, Self::Alignment> =
258 <Self as GetFieldOffset<FN>>::OFFSET_WITH_VIS.to_field_offset();
259}
260
261impl<FN, Ty> GetPubFieldOffset<FN> for Ty where Ty: GetFieldOffset<FN, Privacy = IsPublic> {}
262
263//////////////////////////////////////////////////////////////////////////////////
264
265// Hack to assert that a type implements GetPubFieldOffset,
266// while getting the associated types from GetFieldOffset.
267use alias_helpers::AssertImplsGPFO;
268mod alias_helpers {
269 use super::GetFieldOffset;
270 use crate::privacy::IsPublic;
271
272 pub type AssertImplsGPFO<This, FN> = <This as AssertPublicField<FN>>::This;
273
274 pub trait AssertPublicField<FN>: GetFieldOffset<FN, Privacy = IsPublic> {
275 type This: GetFieldOffset<FN, Privacy = IsPublic>;
276 }
277
278 impl<This, FN> AssertPublicField<FN> for This
279 where
280 This: GetFieldOffset<FN, Privacy = IsPublic>,
281 {
282 type This = This;
283 }
284}
285
286//////////////////////////////////////////////////////////////////////////////////
287
288/// Gets the type of a public field in the `GetPubFieldOffset<FN>` impl for `This`.
289///
290/// # Example
291///
292/// ```rust
293/// use repr_offset::{
294/// for_examples::ReprC,
295/// tstr::TS,
296/// FieldType,
297/// };
298///
299/// type This = ReprC<u8, &'static str, Option<usize>, bool>;
300///
301/// let _: FieldType<This, TS!(a)> = 3_u8;
302/// let _: FieldType<This, TS!(b)> = "hello";
303/// let _: FieldType<This, TS!(c)> = Some(5_usize);
304/// let _: FieldType<This, TS!(d)> = false;
305///
306/// ```
307pub type FieldType<This, FN> = <AssertImplsGPFO<This, FN> as GetFieldOffset<FN>>::Type;
308
309/// Gets the alignment of a public field in the `GetPubFieldOffset<FN>` impl for `This`.
310///
311/// # Example
312///
313/// ```rust
314/// use repr_offset::{
315/// get_field_offset::FieldAlignment,
316/// for_examples::{ReprC, ReprPacked},
317/// tstr::TS,
318/// Aligned, Unaligned,
319/// };
320///
321/// type Inner = ReprPacked<i16, i32, i64, i128>;
322///
323/// type This = ReprC<Inner, &'static str, Option<usize>, bool>;
324///
325/// // Fields directly inside a ReprC are all aligned.
326/// let _: FieldAlignment<This, TS!(a)> = Aligned;
327/// let _: FieldAlignment<This, TS!(b)> = Aligned;
328/// let _: FieldAlignment<This, TS!(c)> = Aligned;
329/// let _: FieldAlignment<This, TS!(d)> = Aligned;
330///
331/// // Fields inside a ReprPacked are all unaligned.
332/// let _: FieldAlignment<This, TS!(a, a)> = Unaligned;
333/// let _: FieldAlignment<This, TS!(a, b)> = Unaligned;
334/// let _: FieldAlignment<This, TS!(a, c)> = Unaligned;
335/// let _: FieldAlignment<This, TS!(a, d)> = Unaligned;
336///
337/// ```
338pub type FieldAlignment<This, FN> = <AssertImplsGPFO<This, FN> as GetFieldOffset<FN>>::Alignment;
339
340////////////////////////////////////////////////////////////////////////////////
341
342/// Gets the type of a (potentially) private field in the `GetFieldOffset<FN>` impl for `This`.
343///
344/// # Warning
345///
346/// Because the field may be private this can break when asking for
347/// the type of fields in types from external crates.
348///
349/// # Example
350///
351/// ```rust
352/// use repr_offset::{
353/// get_field_offset::PrivFieldType,
354/// tstr::TS,
355/// unsafe_struct_field_offsets,
356/// };
357///
358/// use foo::Foo;
359///
360/// let _: PrivFieldType<Foo, TS!(x)> = 3_u8;
361/// let _: PrivFieldType<Foo, TS!(y)> = 5_u16;
362/// let _: PrivFieldType<Foo, TS!(z)> = 8_u32;
363/// let _: PrivFieldType<Foo, TS!(w)> = 13_u64;
364///
365/// mod foo {
366/// use super::*;
367///
368/// #[repr(C)]
369/// pub struct Foo {
370/// x: u8,
371/// pub(super) y: u16,
372/// pub(crate) z: u32,
373/// pub w: u64,
374/// }
375///
376/// repr_offset::unsafe_struct_field_offsets!{
377/// alignment = repr_offset::Aligned,
378///
379/// impl[] Foo {
380/// const OFFSET_X, x: u8;
381/// pub(super) const OFFSET_Y, y: u16;
382/// pub(crate) const OFFSET_Z, z: u32;
383/// pub const OFFSET_W, w: u64;
384/// }
385/// }
386/// }
387///
388/// ```
389///
390pub type PrivFieldType<This, FN> = <This as GetFieldOffset<FN>>::Type;
391
392/// Gets the alignment of a (potentially) private field in the `GetFieldOffset<FN>` impl for `This`.
393///
394/// # Warning
395///
396/// Because the field may be private this can break when asking for
397/// the alignment of fields in types from external crates.
398///
399/// # Example
400///
401/// ```rust
402/// use repr_offset::{
403/// for_examples::ReprPacked,
404/// get_field_offset::PrivFieldAlignment,
405/// tstr::TS,
406/// Aligned, Unaligned,
407/// };
408///
409/// # fn main(){
410/// // Fields in ReprC are all aligned
411/// let _: PrivFieldAlignment<Foo, TS!(x)> = Aligned;
412/// let _: PrivFieldAlignment<Foo, TS!(y)> = Aligned;
413/// let _: PrivFieldAlignment<Foo, TS!(z)> = Aligned;
414/// let _: PrivFieldAlignment<Foo, TS!(w)> = Aligned;
415///
416/// // Fields in ReprPacked are all unaligned
417/// let _: PrivFieldAlignment<Foo, TS!(y, a)> = Unaligned;
418/// let _: PrivFieldAlignment<Foo, TS!(y, b)> = Unaligned;
419/// let _: PrivFieldAlignment<Foo, TS!(y, c)> = Unaligned;
420/// let _: PrivFieldAlignment<Foo, TS!(y, d)> = Unaligned;
421/// # }
422///
423/// mod foo {
424/// use super::*;
425///
426/// type YField = ReprPacked<&'static str, &'static [u8], char, bool>;
427///
428/// #[repr(C)]
429/// pub struct Foo {
430/// x: u8,
431/// pub(super) y: YField,
432/// pub(crate) z: u32,
433/// pub w: u64,
434/// }
435///
436/// repr_offset::unsafe_struct_field_offsets!{
437/// alignment = Aligned,
438///
439/// impl[] Foo {
440/// const OFFSET_X, x: u8;
441/// pub(super) const OFFSET_Y, y: YField;
442/// pub(crate) const OFFSET_Z, z: u32;
443/// pub const OFFSET_W, w: u64;
444/// }
445/// }
446/// }
447///
448/// use foo::Foo;
449///
450///
451/// ```
452///
453pub type PrivFieldAlignment<This, FN> = <This as GetFieldOffset<FN>>::Alignment;
454
455/// Gets the privacy of a field in the `GetFieldOffset<FN>` impl for `This`.
456///
457/// # Warning
458///
459/// Because the field may be private this can break when asking for
460/// the privacy of fields in types from external crates.
461///
462/// # Example
463///
464/// ```rust
465/// use repr_offset::{
466/// get_field_offset::FieldPrivacy,
467/// privacy::{IsPrivate, IsPublic},
468/// tstr::TS,
469/// Aligned,
470/// };
471///
472/// let _: FieldPrivacy<Foo, TS!(x)> = IsPrivate;
473/// let _: FieldPrivacy<Foo, TS!(y)> = IsPrivate;
474/// let _: FieldPrivacy<Foo, TS!(z)> = IsPrivate;
475/// let _: FieldPrivacy<Foo, TS!(w)> = IsPublic;
476///
477/// mod foo {
478/// use super::*;
479///
480/// #[repr(C)]
481/// pub struct Foo {
482/// x: u8,
483/// pub(super) y: u16,
484/// pub(crate) z: u32,
485/// pub w: u64,
486/// }
487///
488/// repr_offset::unsafe_struct_field_offsets!{
489/// alignment = repr_offset::Aligned,
490///
491/// impl[] Foo {
492/// const OFFSET_X, x: u8;
493/// pub(super) const OFFSET_Y, y: u16;
494/// pub(crate) const OFFSET_Z, z: u32;
495/// pub const OFFSET_W, w: u64;
496/// }
497/// }
498/// }
499///
500/// use foo::Foo;
501///
502///
503///
504/// ```
505///
506pub type FieldPrivacy<This, FN> = <This as GetFieldOffset<FN>>::Privacy;
507
508//////////////////////////////////////////////////////////////////////////////////
509
510/// A wrapper around a [`FieldOffset`], with a visibility type parameter
511/// (whether the field is pub or not).
512///
513/// # Type parameters
514///
515/// `S`: The type that contains the field
516///
517/// `V`: The visibility of the field, either [`IsPrivate`] or [`IsPublic`].
518///
519/// `FN`: The name of the field, written using the `repr_offset::tstr::TS` macro,
520/// written as `TS!(field_name)`.
521///
522/// `F`: The type of the field.
523///
524/// `A`: The alignment of the field inside of `S`, either [`Aligned`] or [`Unaligned`].
525///
526///
527/// [`GetFieldOffset::OFFSET_WITH_VIS`]:
528/// ./trait.GetFieldOffset.html#associatedconstant.OFFSET_WITH_VIS
529///
530/// [`FieldOffset`]: ../struct.FieldOffset.html
531///
532/// [`Aligned`]: ../alignment/struct.Aligned.html
533/// [`Unaligned`]: ../alignment/struct.Unaligned.html
534///
535/// [`IsPublic`]: ../privacy/struct.IsPublic.html
536/// [`IsPrivate`]: ../privacy/struct.IsPrivate.html
537///
538///
539#[repr(transparent)]
540pub struct FieldOffsetWithVis<S, V, FN, F, A> {
541 offset: FieldOffset<S, F, A>,
542 _associated_consts_from: PhantomData<fn() -> (FN, V)>,
543 // The type that we got this FieldOffsetWithVis from,
544 // not necessarily same as the one that contains the field,
545 // that is `S`.
546 #[doc(hidden)]
547 pub ac: PhantomData<fn() -> S>,
548}
549
550impl<S, V, FN, F, A> Copy for FieldOffsetWithVis<S, V, FN, F, A> {}
551
552impl<S, V, FN, F, A> Clone for FieldOffsetWithVis<S, V, FN, F, A> {
553 fn clone(&self) -> Self {
554 *self
555 }
556}
557
558impl<S, V, FN, F, A> FieldOffsetWithVis<S, V, FN, F, A> {
559 /// Constructs this `FieldOffsetWithVis` from the `offset` (in bytes) of a field.
560 ///
561 /// # Safety
562 ///
563 /// This method has a superset of the safety requirements of [`FieldOffset::new`].
564 ///
565 /// The `V` type parameter must be:
566 /// - [`IsPublic`]: When the field is `pub`.
567 ///
568 /// - [`IsPrivate`]: When the field has the default (private) visibility,
569 /// or has a visibility smaller or equal to `pub(crate)`.
570 ///
571 /// The `FN` type parameter must be the name of the field using the
572 /// `repr_offset::tstr::TS` macro,
573 /// eg: `TS!(foo)` for the `foo` field.
574 ///
575 /// [`IsPublic`]: ../privacy/struct.IsPublic.html
576 /// [`IsPrivate`]: ../privacy/struct.IsPrivate.html
577 ///
578 /// [`FieldOffset::new`]: ../struct.FieldOffset.html#method.new
579 /// [`FieldOffset`]: ../struct.FieldOffset.html
580 pub const unsafe fn new(offset: usize) -> Self {
581 Self {
582 offset: FieldOffset::new(offset),
583 _associated_consts_from: crate::utils::MakePhantomData::FN_RET,
584 ac: crate::utils::MakePhantomData::FN_RET,
585 }
586 }
587
588 /// Constructs this `FieldOffsetWithVis` from `offset`.
589 ///
590 /// # Safety
591 ///
592 /// The `V` type parameter must be:
593 /// - [`IsPublic`]: When the field is `pub`.
594 ///
595 /// - [`IsPrivate`]: When the field has the default (private) visibility,
596 /// or has a visibility smaller or equal to `pub(crate)`.
597 ///
598 /// The `FN` type parameter must be the name of the field using the
599 /// `repr_offset::tstr::TS` macro,
600 /// eg: `TS!(foo)` for the `foo` field.
601 ///
602 /// [`IsPublic`]: ../privacy/struct.IsPublic.html
603 /// [`IsPrivate`]: ../privacy/struct.IsPrivate.html
604 ///
605 /// [`FieldOffset::new`]: ../struct.FieldOffset.html#method.new
606 /// [`FieldOffset`]: ../struct.FieldOffset.html
607 pub const unsafe fn from_fieldoffset(offset: FieldOffset<S, F, A>) -> Self {
608 Self {
609 offset,
610 _associated_consts_from: crate::utils::MakePhantomData::FN_RET,
611 ac: crate::utils::MakePhantomData::FN_RET,
612 }
613 }
614}
615
616impl<FN, S, F, A> FieldOffsetWithVis<S, IsPublic, FN, F, A> {
617 /// Unwraps this into a [`FieldOffset`] for a public field.
618 ///
619 /// [`FieldOffset`]: ../struct.FieldOffset.html
620 pub const fn to_field_offset(self) -> FieldOffset<S, F, A> {
621 self.offset
622 }
623}
624
625impl<S, V, FN, F, A> FieldOffsetWithVis<S, V, FN, F, A> {
626 /// Unwraps this into a [`FieldOffset`] for a possibly private field.
627 ///
628 /// # Safety
629 ///
630 /// Because the field may be private, modifying its state could cause undefined behavior,
631 /// and is only supposed to be done in a context where the field is accessible.
632 ///
633 /// [`FieldOffset`]: ../struct.FieldOffset.html
634 ///
635 #[inline(always)]
636 pub const unsafe fn private_field_offset(self) -> FieldOffset<S, F, A> {
637 self.offset
638 }
639
640 /// Casts this `FieldOffsetWithVis` to be for a different struct.
641 ///
642 /// This is mostly useful for `#[repr(transparent)]` types to delegate to
643 /// their single field.
644 ///
645 /// # Safety
646 ///
647 /// `SO` must contain a field of type `S` as its first field in memory,
648 /// at offset 0.
649 pub const unsafe fn cast_struct<SO>(self) -> FieldOffsetWithVis<SO, V, FN, F, A> {
650 FieldOffsetWithVis {
651 offset: FieldOffset::new(self.offset.offset()),
652 _associated_consts_from: crate::utils::MakePhantomData::FN_RET,
653 ac: crate::utils::MakePhantomData::FN_RET,
654 }
655 }
656
657 #[doc(hidden)]
658 #[inline(always)]
659 pub const fn infer(self, _struct: &S) {}
660}
661
662////////////////////////////////////////////////////////////////////////////////
663
664#[doc(hidden)]
665pub fn loop_create_mutref<'a, S>(_: PhantomData<fn() -> S>) -> &'a mut S {
666 loop {}
667}
668
669#[doc(hidden)]
670pub fn loop_create_fo<S, F, A>(_: PhantomData<fn() -> S>) -> FieldOffset<S, F, A> {
671 loop {}
672}
673
674#[doc(hidden)]
675pub fn loop_create_val<S>(_: PhantomData<fn() -> S>) -> S {
676 loop {}
677}
678
679////////////////////////////////////////////////////////////////////////////////
680
681#[doc(hidden)]
682pub mod r#unsafe {
683 use super::GetFieldOffset;
684 use crate::FieldOffset;
685
686 #[allow(non_camel_case_types)]
687 pub struct unsafe_get_private_field<S, FN>(S, FN);
688
689 impl<S, FN> unsafe_get_private_field<S, FN>
690 where
691 S: GetFieldOffset<FN>,
692 {
693 #[doc(hidden)]
694 #[allow(non_upper_case_globals)]
695 pub const __unsafe__GET_PRIVATE_FIELD_OFFSET: FieldOffset<S, S::Type, S::Alignment> =
696 unsafe { <S as GetFieldOffset<FN>>::OFFSET_WITH_VIS.private_field_offset() };
697 }
698}