pub enum Type {
Address(Span, Option<payable>),
Bool(Span),
String(Span),
Bytes(Span),
FixedBytes(Span, NonZeroU16),
Int(Span, Option<NonZeroU16>),
Uint(Span, Option<NonZeroU16>),
Array(TypeArray),
Tuple(TypeTuple),
Function(TypeFunction),
Mapping(TypeMapping),
Custom(SolPath),
}
Expand description
A type name.
Solidity reference: https://docs.soliditylang.org/en/latest/grammar.html#a4.SolidityParser.typeName
Variants§
Address(Span, Option<payable>)
address $(payable)?
Bool(Span)
bool
String(Span)
string
Bytes(Span)
bytes
FixedBytes(Span, NonZeroU16)
bytes<size>
Int(Span, Option<NonZeroU16>)
int[size]
Uint(Span, Option<NonZeroU16>)
uint[size]
Array(TypeArray)
$ty[$($size)?]
Tuple(TypeTuple)
$(tuple)? ( $($types,)* )
Function(TypeFunction)
function($($arguments),*) $($attributes)* $(returns ($($returns),+))?
Mapping(TypeMapping)
mapping($key $($key_name)? => $value $($value_name)?)
Custom(SolPath)
A custom type.
Implementations§
Source§impl Type
impl Type
pub fn custom(ident: Ident) -> Self
pub fn peek(lookahead: &Lookahead1<'_>) -> bool
Sourcepub fn parse_ident(ident: Ident) -> Result<Self>
pub fn parse_ident(ident: Ident) -> Result<Self>
Parses an identifier as an elementary type name.
Note that you will have to check for the existence of a payable
keyword separately.
Sourcepub fn parse_payable(self, input: ParseStream<'_>) -> Result<Self>
pub fn parse_payable(self, input: ParseStream<'_>) -> Result<Self>
Parses the payable
keyword from the input stream if this type is an
address.
Sourcepub fn is_one_word(
&self,
custom_is_value_type: impl Fn(&SolPath) -> bool,
) -> bool
👎Deprecated: use is_value_type
instead
pub fn is_one_word( &self, custom_is_value_type: impl Fn(&SolPath) -> bool, ) -> bool
is_value_type
insteadReturns whether this type is ABI-encoded as a single EVM word (32 bytes).
This is the same as is_value_type
.
Sourcepub fn is_abi_dynamic(&self) -> bool
pub fn is_abi_dynamic(&self) -> bool
Returns whether this type is dynamic according to ABI rules.
Note that this does not account for custom types, such as UDVTs.
Sourcepub fn is_value_type(
&self,
custom_is_value_type: impl Fn(&SolPath) -> bool,
) -> bool
pub fn is_value_type( &self, custom_is_value_type: impl Fn(&SolPath) -> bool, ) -> bool
Returns whether this type is a value type.
These types’ variables are always passed by value.
custom_is_value_type
accounts for custom value types.
See the Solidity docs for more information.
Sourcepub fn is_value_type_simple(&self) -> bool
pub fn is_value_type_simple(&self) -> bool
Returns whether this type is a simple value type.
See is_value_type
for more information.
pub const fn is_array(&self) -> bool
pub const fn is_tuple(&self) -> bool
pub const fn is_custom(&self) -> bool
Sourcepub fn has_custom(&self) -> bool
pub fn has_custom(&self) -> bool
Recurses into this type and returns whether it contains a custom type.
Sourcepub fn has_custom_simple(&self) -> bool
pub fn has_custom_simple(&self) -> bool
Same as has_custom
, but Function
returns false
rather than recursing into its arguments and return types.
Sourcepub fn peel_arrays(&self) -> &Self
pub fn peel_arrays(&self) -> &Self
Returns the inner type.
Sourcepub fn abi_name(&self) -> String
pub fn abi_name(&self) -> String
Returns the Solidity ABI name for this type. This is tuple
for custom types, otherwise the
same as Display
.
Sourcepub fn abi_name_raw(&self, s: &mut String)
pub fn abi_name_raw(&self, s: &mut String)
Returns the Solidity ABI name for this type. This is tuple
for custom types, otherwise the
same as Display
.