feat(interface-types) Add the Vec1 type to represent a non-empty vector.

`Vec1` is used by `RecordType` to ensure that a record have at least 1
field. Then an `InterfaceValue::Record` is ensured to get at least one
value with the type-checking pass.
This commit is contained in:
Ivan Enderlin
2020-04-03 16:13:44 +02:00
parent 643659801c
commit 419dcc6415
12 changed files with 136 additions and 39 deletions

View File

@ -1,3 +1,28 @@
/// This macro creates a `Vec1` by checking at compile-time that its
/// invariant holds.
#[allow(unused)]
macro_rules! vec1 {
($item:expr; 0) => {
compile_error!("Cannot create an empty `Vec1`, it violates its invariant.")
};
() => {
compile_error!("Cannot create an empty `Vec1`, it violates its invariant.")
};
($item:expr; $length:expr) => {
{
crate::vec1::Vec1::new(vec![$item; $length]).unwrap()
}
};
($($item:expr),+ $(,)?) => {
{
crate::vec1::Vec1::new(vec![$($item),*]).unwrap()
}
};
}
/// This macro runs a parser, extracts the next input and the parser
/// output, and positions the next input on `$input`.
macro_rules! consume {