Param

Struct Param 

Source
pub struct Param {
    pub components: Vec<Param>,
    pub internal_type: Option<InternalType>,
    /* private fields */
}
Expand description

JSON specification of a parameter.

Parameters are the inputs and outputs of Functions, and the fields of Errors.

Fields§

§components: Vec<Param>

If the parameter is a compound type (a struct or tuple), a list of the parameter’s components, in order. Empty otherwise

§internal_type: Option<InternalType>

The internal type of the parameter. This type represents the type that the author of the Solidity contract specified. E.g. for a contract, this will be contract MyContract while the type field will be address.

Implementations§

Source§

impl Param

Source

pub fn parse(input: &str) -> Result<Self>

Parse a parameter from a Solidity parameter string.

§Examples
assert_eq!(
    Param::parse("uint256[] foo"),
    Ok(Param {
        name: "foo".into(),
        ty: "uint256[]".into(),
        components: vec![],
        internal_type: None,
    })
);
Source

pub fn new( name: &str, ty: &str, components: Vec<Self>, internal_type: Option<InternalType>, ) -> Result<Self>

Validate and create new instance of Param.

Source

pub fn name(&self) -> &str

The name of the parameter. This function always returns either an empty slice, or a valid Solidity identifier.

Source

pub const fn internal_type(&self) -> Option<&InternalType>

The internal type of the parameter.

Source

pub fn is_udt(&self) -> bool

True if the parameter is a UDT (user-defined type).

A UDT will have

  • an internal type that does not match its canonical type
  • no space in its internal type (as it does not have a keyword body)

Any Other specifier will definitely be a UDT if it contains a contract.

Source

pub const fn is_struct(&self) -> bool

True if the parameter is a struct.

Source

pub const fn is_enum(&self) -> bool

True if the parameter is an enum.

Source

pub const fn is_contract(&self) -> bool

True if the parameter is a contract.

Source

pub fn udt_specifier(&self) -> Option<TypeSpecifier<'_>>

The UDT specifier is a TypeSpecifier containing the UDT name and any array sizes. It is computed from the internal_type. If this param is not a UDT, this function will return None.

Source

pub fn struct_specifier(&self) -> Option<TypeSpecifier<'_>>

The struct specifier is a TypeSpecifier containing the struct name and any array sizes. It is computed from the internal_type If this param is not a struct, this function will return None.

Source

pub fn enum_specifier(&self) -> Option<TypeSpecifier<'_>>

The enum specifier is a TypeSpecifier containing the enum name and any array sizes. It is computed from the internal_type. If this param is not a enum, this function will return None.

Source

pub fn contract_specifier(&self) -> Option<TypeSpecifier<'_>>

The struct specifier is a TypeSpecifier containing the contract name and any array sizes. It is computed from the internal_type If this param is not a struct, this function will return None.

Source

pub fn is_simple_type(&self) -> bool

True if the type is simple

Source

pub fn is_complex_type(&self) -> bool

True if the type is complex (tuple or struct)

Source

pub fn selector_type_raw(&self, s: &mut String)

Formats the canonical type of this parameter into the given string.

This is used to encode the preimage of a function or error selector.

Source

pub fn full_selector_type_raw(&self, s: &mut String)

Formats the canonical type of this parameter into the given string including then names of the params.

Source

pub fn selector_type(&self) -> Cow<'_, str>

Returns the canonical type of this parameter.

This is used to encode the preimage of a function or error selector.

Trait Implementations§

Source§

impl Clone for Param

Source§

fn clone(&self) -> Param

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 Debug for Param

Source§

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

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

impl Default for Param

Source§

fn default() -> Param

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Param

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Param

Source§

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

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

impl FromStr for Param

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Param

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Param

Source§

fn eq(&self, other: &Param) -> 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 Serialize for Param

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Param

Source§

impl StructuralPartialEq for Param

Auto Trait Implementations§

§

impl Freeze for Param

§

impl RefUnwindSafe for Param

§

impl Send for Param

§

impl Sync for Param

§

impl Unpin for Param

§

impl UnwindSafe for Param

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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: 64 bytes