Skip to content

Commit

Permalink
feat(json-abi): add AbiItem::json_type (#797)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Oct 30, 2024
1 parent ce59660 commit a3d3f89
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/json-abi/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)*}
}
}
};
}

Expand Down

0 comments on commit a3d3f89

Please sign in to comment.