add helper methods for accessing struct tail
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user