abi_stable/type_layout/
construction.rs
1use super::*;
2
3#[allow(non_camel_case_types)]
6#[doc(hidden)]
7#[derive(Copy, Clone)]
8pub struct _private_TypeLayoutDerive {
9 pub shared_vars: &'static SharedVars,
10 pub mono: &'static MonoTypeLayout,
11 pub abi_consts: AbiConsts,
12 pub data: GenericTLData,
13 pub tag: Option<&'static Tag>,
14 pub extra_checks: Option<&'static ManuallyDrop<StoredExtraChecks>>,
15}
16
17#[allow(non_camel_case_types)]
18#[doc(hidden)]
19#[derive(Copy, Clone)]
20pub struct _private_MonoTypeLayoutDerive {
21 pub name: RStr<'static>,
22 pub item_info: ItemInfo,
23 pub data: MonoTLData,
24 pub generics: CompGenericParams,
25 pub repr_attr: ReprAttr,
26 pub mod_refl_mode: ModReflMode,
27 pub phantom_fields: RSlice<'static, CompTLFieldRepr>,
28 pub shared_vars: MonoSharedVars,
29}
30
31#[repr(C)]
33#[derive(Debug, Copy, Clone, PartialEq, Eq, StableAbi)]
34#[sabi(unsafe_sabi_opaque_fields)]
35pub struct ItemInfo {
36 package_and_version: RStr<'static>,
39 pub line: u32,
41 pub mod_path: ModPath,
44}
45
46impl ItemInfo {
47 #[doc(hidden)]
48 pub const fn new(package_and_version: &'static str, line: u32, mod_path: ModPath) -> Self {
49 Self {
50 package_and_version: RStr::from_str(package_and_version),
51 line,
52 mod_path,
53 }
54 }
55
56 pub const fn primitive() -> Self {
58 Self {
59 package_and_version: RStr::from_str("std;1.0.0"),
60 line: 0,
61 mod_path: ModPath::PRELUDE,
62 }
63 }
64
65 pub const fn std_type_in(mod_path: NulStr<'static>) -> Self {
67 Self {
68 package_and_version: RStr::from_str("std;1.0.0"),
69 line: 0,
70 mod_path: ModPath::inside(mod_path),
71 }
72 }
73
74 pub const fn package_and_mod(
80 package_and_version: &'static str,
81 mod_path: NulStr<'static>,
82 ) -> Self {
83 Self {
84 package_and_version: RStr::from_str(package_and_version),
85 line: 0,
86 mod_path: ModPath::inside(mod_path),
87 }
88 }
89
90 pub fn package_and_version(&self) -> (&'static str, &'static str) {
92 let pav = self.package_and_version.as_str();
93 match pav.find(';') {
94 Some(separator) => (&pav[..separator], &pav[(separator + 1)..]),
95 None => (pav, ""),
96 }
97 }
98
99 pub fn package(&self) -> &'static str {
101 self.package_and_version().0
102 }
103
104 pub fn version(&self) -> &'static str {
106 self.package_and_version().1
107 }
108}