From a3d3f89f1d861e9cad1067706192bd697a9972a5 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Wed, 30 Oct 2024 18:58:21 +0100 Subject: [PATCH] feat(json-abi): add `AbiItem::json_type` (#797) --- crates/json-abi/src/item.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/json-abi/src/item.rs b/crates/json-abi/src/item.rs index 89ed2a119..99e094929 100644 --- a/crates/json-abi/src/item.rs +++ b/crates/json-abi/src/item.rs @@ -58,6 +58,25 @@ macro_rules! abi_items { )*} } } + + impl AbiItem<'_> { + /// Returns the JSON type of the item as a string. + /// + /// # Examples + /// + /// ``` + /// # use alloy_json_abi::AbiItem; + /// let item = AbiItem::parse("function f()")?; + /// assert_eq!(item.json_type(), "function"); + /// # Ok::<_, alloy_json_abi::parser::Error>(()) + /// ``` + #[inline] + pub const fn json_type(&self) -> &'static str { + match self {$( + Self::$name(_) => $name_lower, + )*} + } + } }; }