pub enum Params {
Null,
Boolean(bool),
Integer(i64),
BigInteger(BigInt),
Decimal(BigDecimal),
Text(String),
ByteArray(Vec<u8>),
Array(Vec<Params>),
Dict(BTreeMap<String, Params>),
}Expand description
Represents different types of operation parameters.
This enum provides a type-safe way to handle various data types used in blockchain operations, including primitive types, collections, and special types like BigInteger.
Variants§
Null
Represents a null value
Boolean(bool)
Represents a boolean value (true/false)
Integer(i64)
Represents a 64-bit signed integer
BigInteger(BigInt)
Represents an arbitrary-precision integer using BigInt
Decimal(BigDecimal)
Represents an arbitrary-precision decimal using BigDecimal
Text(String)
Represents a UTF-8 encoded string
ByteArray(Vec<u8>)
Represents a raw byte array
Array(Vec<Params>)
Represents an ordered collection of Params
Dict(BTreeMap<String, Params>)
Represents a key-value mapping where keys are strings
Implementations§
Source§impl Params
impl Params
Sourcepub fn decimal_to_string(val: Box<f64>) -> String
pub fn decimal_to_string(val: Box<f64>) -> String
Sourcepub fn dict_to_array(self) -> Vec<Params>
pub fn dict_to_array(self) -> Vec<Params>
Sourcepub fn to_struct<T>(&self) -> Result<T, String>
pub fn to_struct<T>(&self) -> Result<T, String>
Converts a dictionary parameter to a Rust struct.
§Type Parameters
T- The target struct type that implements Default + Debug + Deserialize
§Returns
Result containing either the converted struct or an error message
§Example
#[derive(Debug, Default, serde::Deserialize)]
struct MyStruct {
field: String,
value: i64,
}
let dict = Params::Dict(/* ... */);
let result: Result<MyStruct, String> = dict.to_struct();Sourcepub fn to_json_value(&self) -> Value
pub fn to_json_value(&self) -> Value
Converts the parameter to a serde_json::Value.
This method handles all parameter types, including complex types like BigInteger and ByteArray.
§Returns
JSON representation of the parameter
Sourcepub fn from_struct<T>(struct_instance: &T) -> Params
pub fn from_struct<T>(struct_instance: &T) -> Params
Creates a parameter from a Rust struct.
§Type Parameters
T- The source struct type that implements Debug + Serialize
§Arguments
struct_instance- Reference to the struct to convert
§Returns
Dictionary parameter containing the struct’s fields
§Example
#[derive(Debug, serde::Serialize)]
struct MyStruct {
field: String,
value: i64,
}
let my_struct = MyStruct { field: "test".into(), value: 42 };
let params = Params::from_struct(&my_struct);Sourcepub fn from_struct_to_list<T>(struct_instance: &T) -> Vec<Params>
pub fn from_struct_to_list<T>(struct_instance: &T) -> Vec<Params>
Creates a list of parameters from a Rust struct.
Similar to from_struct, but returns a vector of values instead of a dictionary.
§Type Parameters
T- The source struct type that implements Debug + Serialize
§Arguments
struct_instance- Reference to the struct to convert
§Returns
Vector of parameters containing the struct’s field values
Sourcepub fn debug_print(&self)
pub fn debug_print(&self)
Prints debug information about the parameter.
This method is only available in debug builds and provides detailed information about the parameter’s content.
§Arguments
self- The parameter to debug print
Trait Implementations§
Source§impl From<Params> for BigDecimal
Converts Params to BigDecimal.
impl From<Params> for BigDecimal
Converts Params to BigDecimal.
§Panics
Panics if the Params variant is not Params::Decimal.
Source§impl From<Params> for BigInt
Converts Params to BigInt.
impl From<Params> for BigInt
Converts Params to BigInt.
§Panics
Panics if the Params variant is not Params::BigInteger.
Source§impl From<Params> for String
Converts Params to String.
impl From<Params> for String
Converts Params to String.
§Panics
Panics if the Params variant is not Params::Text.
Source§impl From<Params> for Vec<u8>
Converts Params to Vec<u8>.
impl From<Params> for Vec<u8>
Converts Params to Vec<u8>.
§Panics
Panics if the Params variant is not Params::ByteArray.
Source§impl From<Params> for bool
Converts Params to bool.
impl From<Params> for bool
Converts Params to bool.
§Panics
Panics if the Params variant is not Params::Boolean.
Source§impl From<Params> for i64
Converts Params to i64.
impl From<Params> for i64
Converts Params to i64.
§Panics
Panics if the Params variant is not Params::Integer.
Source§impl<'a> GTVParams for Params
impl<'a> GTVParams for Params
fn to_writer(&self, writer: &mut Writer<'_>) -> WriteResult
Source§impl Into<BTreeMap<String, Params>> for Params
Implements conversion from Params to BTreeMap<String, Params>.
impl Into<BTreeMap<String, Params>> for Params
Implements conversion from Params to BTreeMap<String, Params>.
This implementation allows converting a Dict parameter into a BTreeMap of string keys and parameter values.
§Panics
Panics if the parameter is not a Dict type
Source§impl Into<Vec<Params>> for Params
Implements conversion from Params to Vec<Params>.
impl Into<Vec<Params>> for Params
Implements conversion from Params to Vec<Params>.
This implementation allows converting an Array parameter into a vector of parameters.
§Panics
Panics if the parameter is not an Array type