pub struct SchemaEnum {
pub dbg_name: String,
pub variants: Vec<Variant>,
pub discriminant_size: u8,
/* private fields */
}Expand description
Schema for an enum.
An enum is serialized as its u8 variant discriminant followed by all the field for that variant. The name of each variant, as well as its order in the enum (the discriminant), is significant. The memory format is given by ‘has_explicit_repr’, ‘discriminant_size’, ‘size’, ‘alignment’ and the vairous variants.
Note: If ‘has_explicit_repr’ is false, the memory format is unspecified.
Fields§
§dbg_name: StringDiagnostic name
variants: Vec<Variant>Variants of enum
discriminant_size: u8If this is a repr(uX)-enum, then the size of the discriminant, in bytes. Valid values are 1, 2, or 4. Otherwise, this is the number of bytes needed to represent the discriminant. In either case, this is the size of the enum in the disk-format.
Implementations§
Source§impl SchemaEnum
impl SchemaEnum
Sourcepub fn new(
dbg_name: String,
discriminant_size: u8,
variants: Vec<Variant>,
) -> SchemaEnum
pub fn new( dbg_name: String, discriminant_size: u8, variants: Vec<Variant>, ) -> SchemaEnum
Create a new SchemaEnum instance. Arguments:
- dbg_name - Name of the enum type.
- discriminant_size: If this is a repr(uX)-enum, then the size of the discriminant, in bytes. Valid values are 1, 2, or 4. Otherwise, this is the number of bytes needed to represent the discriminant. In either case, this is the size of the enum in the disk-format.
- variants - The variants of the enum
Sourcepub fn new_unsafe(
dbg_name: String,
variants: Vec<Variant>,
discriminant_size: u8,
has_explicit_repr: bool,
size: Option<usize>,
alignment: Option<usize>,
) -> SchemaEnum
pub fn new_unsafe( dbg_name: String, variants: Vec<Variant>, discriminant_size: u8, has_explicit_repr: bool, size: Option<usize>, alignment: Option<usize>, ) -> SchemaEnum
Create a new SchemaEnum instance. Arguments:
- dbg_name - Name of the enum type.
- variants - The variants of the enum
- discriminant_size: If this is a repr(uX)-enum, then the size of the discriminant, in bytes. Valid values are 1, 2, or 4. Otherwise, this is the number of bytes needed to represent the discriminant. In either case, this is the size of the enum in the disk-format.
- has_explicit_repr: True if this enum type has a repr(uX) attribute, and thus a predictable memory layout.
- size: The size of the enum (
std::mem::size_of::<TheEnum>()), if known - alignment: The alignment of the enum (
std::mem::align_of::<TheEnum>())
§Safety
The argument ‘has_explicit_repr’ must only be true if the enum in fact has a #[repr(uX)] attribute. The size and alignment must be correct for the type.
Trait Implementations§
Source§impl Clone for SchemaEnum
impl Clone for SchemaEnum
Source§fn clone(&self) -> SchemaEnum
fn clone(&self) -> SchemaEnum
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more