TypeSpecifier

Struct 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 parse_eip712(s: &'a str) -> Result<Self>

Available on crate feature eip712 only.

Parse a type specifier from a string with support for : in identifiers.

Extends the standard type parsing.

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 duplicate 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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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>

Source§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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>,

Source§

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>,

Source§

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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 40 bytes