summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ir/context.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/ir/context.rs b/src/ir/context.rs
index 5ebcfc28..f9efbf05 100644
--- a/src/ir/context.rs
+++ b/src/ir/context.rs
@@ -154,6 +154,25 @@ item_id_newtype! {
unchecked = as_var_id_unchecked;
}
+item_id_newtype! {
+ /// An identifier for an `Item` whose `ItemKind` is known to be
+ /// `ItemKind::Function`.
+ pub struct FunctionId(ItemId)
+ where
+ /// Convert this `ItemId` into a `FunctionId` if its associated item is a function,
+ /// otherwise return `None`.
+ checked = as_function_id with is_function,
+
+ /// Convert this `ItemId` into a `FunctionId`.
+ ///
+ /// If this `ItemId` does not point to a function, then panic.
+ expected = expect_function_id,
+
+ /// Convert this `ItemId` into a `FunctionId` without actually checking whether
+ /// this id actually points to a `Function`.
+ unchecked = as_function_id_unchecked;
+}
+
impl From<ItemId> for usize {
fn from(id: ItemId) -> usize {
id.0