Struct alloy_sol_type_parser::TypeSpecifier

source ·
pub struct TypeSpecifier<'a> {
    pub span: &'a str,
    pub stem: TypeStem<'a>,
    pub sizes: Vec<Option<NonZeroUsize>>,
}
Expand description

Represents a type-name. Consists of an identifier and optional array sizes.

A type specifier has a stem, which is TypeStem representing either a RootType or a TupleSpecifier, and a list of array sizes. The array sizes are in innermost-to-outermost order. An empty array size vec indicates that the specified type is not an array

Type specifier examples:

  • uint256
  • uint256[2]
  • uint256[2][]
  • (uint256,uint256)
  • (uint256,uint256)[2]
  • MyStruct
  • MyStruct[2]

https://docs.soliditylang.org/en/latest/grammar.html#a4.SolidityParser.typeName

§Compatibility with JSON ABI

This type supports the internalType semantics for JSON-ABI compatibility.

Examples of valid JSON ABI internal types:

  • contract MyContract
  • struct MyStruct
  • enum MyEnum
  • struct MyContract.MyStruct\[333\]
  • enum MyContract.MyEnum[][][][][][]
  • MyValueType

§Examples

let spec = TypeSpecifier::parse("uint256[2][]")?;
assert_eq!(spec.span(), "uint256[2][]");
assert_eq!(spec.stem.span(), "uint256");
// The sizes are in innermost-to-outermost order.
assert_eq!(spec.sizes.as_slice(), &[NonZeroUsize::new(2), None]);

Fields§

§span: &'a str

The full span of the specifier.

§stem: TypeStem<'a>

The type stem, which is either a root type or a tuple type.

§sizes: Vec<Option<NonZeroUsize>>

Array sizes, in innermost-to-outermost order. If the size is None, then the array is dynamic. If the size is Some, then the array is fixed-size. If the vec is empty, then the type is not an array.

Implementations§

source§

impl<'a> TypeSpecifier<'a>

source

pub fn parse(s: &'a str) -> Result<Self>

Parse a type specifier from a string.

source

pub fn parser(input: &mut &'a str) -> PResult<Self>

winnow parser for this type.

source

pub const fn span(&self) -> &'a str

Returns the type stem as a string.

source

pub const fn stem(&self) -> &TypeStem<'_>

Returns the type stem.

source

pub fn try_basic_solidity(&self) -> Result<()>

Returns true if the type is a basic Solidity type.

source

pub fn is_array(&self) -> bool

Returns true if this type is an array.

Trait Implementations§

source§

impl AsRef<str> for TypeSpecifier<'_>

source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'a> Clone for TypeSpecifier<'a>

source§

fn clone(&self) -> TypeSpecifier<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for TypeSpecifier<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> PartialEq for TypeSpecifier<'a>

source§

fn eq(&self, other: &TypeSpecifier<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> TryFrom<&'a str> for TypeSpecifier<'a>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(s: &'a str) -> Result<Self>

Performs the conversion.
source§

impl<'a> Eq for TypeSpecifier<'a>

source§

impl<'a> StructuralPartialEq for TypeSpecifier<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for TypeSpecifier<'a>

§

impl<'a> RefUnwindSafe for TypeSpecifier<'a>

§

impl<'a> Send for TypeSpecifier<'a>

§

impl<'a> Sync for TypeSpecifier<'a>

§

impl<'a> Unpin for TypeSpecifier<'a>

§

impl<'a> UnwindSafe for TypeSpecifier<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.