pub struct ItemFunction {
pub attrs: Vec<Attribute>,
pub kind: FunctionKind,
pub name: Option<SolIdent>,
pub paren_token: Option<Paren>,
pub parameters: ParameterList,
pub attributes: FunctionAttributes,
pub returns: Option<Returns>,
pub body: FunctionBody,
}
Expand description
A function, constructor, fallback, receive, or modifier definition:
function helloWorld() external pure returns(string memory);
.
Solidity reference: https://docs.soliditylang.org/en/latest/grammar.html#a4.SolidityParser.functionDefinition
Fields§
§attrs: Vec<Attribute>
The syn
attributes of the function.
kind: FunctionKind
§name: Option<SolIdent>
§paren_token: Option<Paren>
Parens are optional for modifiers: https://docs.soliditylang.org/en/latest/grammar.html#a4.SolidityParser.modifierDefinition
parameters: ParameterList
§attributes: FunctionAttributes
The Solidity attributes of the function.
returns: Option<Returns>
The optional return types of the function.
body: FunctionBody
Implementations§
Source§impl ItemFunction
impl ItemFunction
Sourcepub fn new(kind: FunctionKind, name: Option<SolIdent>) -> Self
pub fn new(kind: FunctionKind, name: Option<SolIdent>) -> Self
Create a new function of the given kind.
Sourcepub fn new_getter(name: SolIdent, ty: Type) -> Self
pub fn new_getter(name: SolIdent, ty: Type) -> Self
Create a new function with the given name and arguments.
Note that:
- the type is not validated
- structs/array of structs in return position are not expanded
- the body is not set
The attributes are set to public view
.
See the Solidity documentation for more details on how getters are generated.
Sourcepub fn from_variable_definition(var: VariableDefinition) -> Self
pub fn from_variable_definition(var: VariableDefinition) -> Self
Creates a new function from a variable definition.
The function will have the same name and the variable type’s will be the
return type. The variable attributes are ignored, and instead will
always generate public returns
.
See new_getter
for more details.
Sourcepub fn name(&self) -> &SolIdent
pub fn name(&self) -> &SolIdent
Returns the name of the function.
§Panics
Panics if the function has no name. This is the case when kind
is not
Function
.
Sourcepub fn has_implementation(&self) -> bool
pub fn has_implementation(&self) -> bool
Returns true if the function has a body.
Sourcepub fn return_type(&self) -> Option<Type>
pub fn return_type(&self) -> Option<Type>
Returns the function’s return tuple type.
Sourcepub fn body_mut(&mut self) -> Option<&mut Vec<Stmt>>
pub fn body_mut(&mut self) -> Option<&mut Vec<Stmt>>
Returns a mutable reference to the function’s body, if any.
pub fn into_body(self) -> Result<Vec<Stmt>, Self>
Trait Implementations§
Source§impl Clone for ItemFunction
impl Clone for ItemFunction
Source§fn clone(&self) -> ItemFunction
fn clone(&self) -> ItemFunction
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for ItemFunction
impl Debug for ItemFunction
Source§impl Display for ItemFunction
impl Display for ItemFunction
Source§impl Parse for ItemFunction
impl Parse for ItemFunction
fn parse(input: ParseStream<'_>) -> Result<Self>
Source§impl Spanned for ItemFunction
impl Spanned for ItemFunction
Source§fn span(&self) -> Span
fn span(&self) -> Span
Span
covering the complete contents of this syntax tree
node, or Span::call_site()
if this node is empty.