Skip to content

Commit

Permalink
feat(json-abi): add AbiItem::json_type (alloy-rs#797)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored and ZelionD committed Nov 11, 2024
1 parent ef92ba5 commit eb2c84c
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 eb2c84c

Please sign in to comment.