add helper methods for accessing struct tail

This commit is contained in:
Lukas Markeffsky
2023-07-05 20:44:24 +02:00
parent e3de14e463
commit 7aa5f39d3b
9 changed files with 31 additions and 34 deletions

View File

@@ -2028,6 +2028,22 @@ impl VariantDef {
&self.fields[FieldIdx::from_u32(0)]
}
/// Returns the last field in this variant, if present.
#[inline]
pub fn tail_opt(&self) -> Option<&FieldDef> {
self.fields.raw.last()
}
/// Returns the last field in this variant.
///
/// # Panics
///
/// Panics, if the variant has no fields.
#[inline]
pub fn tail(&self) -> &FieldDef {
self.tail_opt().expect("expected unsized ADT to have a tail field")
}
}
impl PartialEq for VariantDef {