xso: add support for extracting tuples

This commit is contained in:
Jonas Schäfer 2024-08-09 16:41:21 +02:00
commit 1ecb95881c
5 changed files with 259 additions and 62 deletions

View file

@ -552,6 +552,17 @@ impl Compound {
})
}
/// Return a reference to this compound's only field's type.
///
/// If the compound does not have exactly one field, this function returns
/// None.
pub(crate) fn single_ty(&self) -> Option<&Type> {
if self.fields.len() > 1 {
return None;
}
self.fields.get(0).map(|x| x.ty())
}
/// Construct a tuple type with this compound's field's types in the same
/// order as they appear in the compound.
pub(crate) fn to_tuple_ty(&self) -> TypeTuple {
@ -574,4 +585,9 @@ impl Compound {
.collect(),
}
}
/// Return the number of fields in this compound.
pub(crate) fn field_count(&self) -> usize {
self.fields.len()
}
}