pub struct Function {
pub name: String,
pub inputs: Vec<Param>,
pub outputs: Vec<Param>,
pub state_mutability: StateMutability,
}
Expand description
A JSON ABI function.
Fields§
§name: String
The name of the function.
inputs: Vec<Param>
The input types of the function. May be empty.
outputs: Vec<Param>
The output types of the function. May be empty.
state_mutability: StateMutability
The state mutability of the function.
Implementations§
Source§impl Function
impl Function
Sourcepub fn parse(s: &str) -> Result<Self>
pub fn parse(s: &str) -> Result<Self>
Parses a Solidity function signature string:
$(function)? $name($($inputs),*) [visibility] [s_mutability] $(returns ($($outputs),+))?
Note:
- visibility is ignored
If you want to parse a generic Human-Readable ABI string, use AbiItem::parse
.
§Examples
Basic usage:
assert_eq!(
Function::parse("foo(bool bar)"),
Ok(Function {
name: "foo".to_string(),
inputs: vec![Param::parse("bool bar").unwrap()],
outputs: vec![],
state_mutability: StateMutability::NonPayable,
}),
);
Functions also support parsing output parameters:
assert_eq!(
Function::parse("function toString(uint number) external view returns (string s)"),
Ok(Function {
name: "toString".to_string(),
inputs: vec![Param::parse("uint number").unwrap()],
outputs: vec![Param::parse("string s").unwrap()],
state_mutability: StateMutability::View,
}),
);
Sourcepub fn signature(&self) -> String
pub fn signature(&self) -> String
Returns this function’s signature: $name($($inputs),*)
.
This is the preimage input used to compute the selector.
Sourcepub fn signature_with_outputs(&self) -> String
pub fn signature_with_outputs(&self) -> String
Returns this function’s full signature:
$name($($inputs),*)($(outputs),*)
.
This is the same as signature
, but also includes
the output types.
Sourcepub fn full_signature(&self) -> String
pub fn full_signature(&self) -> String
Returns this function’s full signature including names of params:
function $name($($inputs $names),*) state_mutability returns ($($outputs $names),*)
.
This is a full human-readable string, including all parameter names, any optional modifiers (e.g. view, payable, pure) and white-space to aid in human readability. This is useful for storing a string which can still fully reconstruct the original Fragment
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Function
impl<'de> Deserialize<'de> for Function
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Function
impl StructuralPartialEq for Function
Auto Trait Implementations§
impl Freeze for Function
impl RefUnwindSafe for Function
impl Send for Function
impl Sync for Function
impl Unpin for Function
impl UnwindSafe for Function
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)