abi_stable/prefix_type/
layout.rs

1use crate::{std_types::RStr, type_layout::MonoTypeLayout};
2
3/// Represents the layout of a prefix-type,for use in error messages.
4#[repr(C)]
5#[derive(Debug, Copy, Clone, StableAbi)]
6// #[derive(Debug, Copy, Clone, PartialEq, StableAbi)]
7pub struct PTStructLayout {
8    /// The stringified generic parameters.
9    pub generics: RStr<'static>,
10    /// The layout information of the type which doesn't depend on generic parameters
11    pub mono_layout: &'static MonoTypeLayout,
12}
13
14//////////////////////////////////////////////////////////////
15
16impl PTStructLayout {
17    /// Constructs a `PTStructLayout`.
18    pub const fn new(generics: RStr<'static>, mono_layout: &'static MonoTypeLayout) -> Self {
19        Self {
20            generics,
21            mono_layout,
22        }
23    }
24
25    /// Gets an iterator over the names of the fields.
26    #[inline]
27    pub fn get_field_names(&self) -> impl Iterator<Item = &'static str> {
28        self.mono_layout.field_names()
29    }
30
31    /// Gets a `Vec` with the names of the fields.
32    #[inline]
33    pub fn get_field_names_vec(&self) -> Vec<&'static str> {
34        self.mono_layout.field_names().collect()
35    }
36
37    /// Gets the name of the `ith` field, returning `None` if there is no `ith` field.
38    #[inline]
39    pub fn get_field_name(&self, ith: usize) -> Option<&'static str> {
40        self.mono_layout.get_field_name(ith)
41    }
42}