postchain_client::utils::operation

Enum Params

Source
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

Source

pub fn decimal_to_string(val: Box<f64>) -> String

Converts a boxed f64 value to its string representation.

§Arguments
  • val - Boxed f64 value to convert
§Returns

String representation of the decimal value

Source

pub fn dict_to_array(self) -> Vec<Params>

Converts a dictionary parameter to an array of its values.

§Arguments
  • self - Dictionary parameter to convert
§Returns

Vector containing the values from the dictionary

§Panics

Panics if self is not a Params::Dict

Source

pub fn is_empty(self) -> bool

Checks if the parameter value is empty.

Works with Array, Dict, ByteArray, and Text parameter types.

§Returns

true if the parameter value is empty

§Panics

Panics if called on parameter types that don’t support emptiness check

Source

pub fn len(self) -> usize

Returns the length of the parameter value.

Works with Array, Dict, ByteArray, and Text parameter types.

§Returns

Length of the parameter value

§Panics

Panics if called on parameter types that don’t support length

Source

pub fn to_struct<T>(&self) -> Result<T, String>
where T: Default + Debug + for<'de> Deserialize<'de>,

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();
Source

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

Source

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);
Source

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

Source

pub fn from_struct_to_vec<T>(struct_instance: &T) -> Vec<(String, Params)>
where T: Debug + Serialize,

Converts a struct into a Vec<(String, Params)>.

§Type Parameters
  • T - The struct type that implements Debug + Serialize
§Arguments
  • struct_instance - Reference to the struct to convert
§Returns

Vector of tuples containing string keys and Params values

Source

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 Clone for Params

Source§

fn clone(&self) -> Params

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

Source§

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

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

impl From<Params> for BigDecimal

Converts Params to BigDecimal.

§Panics

Panics if the Params variant is not Params::Decimal.

Source§

fn from(value: Params) -> Self

Converts to this type from the input type.
Source§

impl From<Params> for BigInt

Converts Params to BigInt.

§Panics

Panics if the Params variant is not Params::BigInteger.

Source§

fn from(value: Params) -> Self

Converts to this type from the input type.
Source§

impl From<Params> for String

Converts Params to String.

§Panics

Panics if the Params variant is not Params::Text.

Source§

fn from(value: Params) -> Self

Converts to this type from the input type.
Source§

impl From<Params> for Vec<u8>

Converts Params to Vec<u8>.

§Panics

Panics if the Params variant is not Params::ByteArray.

Source§

fn from(value: Params) -> Self

Converts to this type from the input type.
Source§

impl From<Params> for bool

Converts Params to bool.

§Panics

Panics if the Params variant is not Params::Boolean.

Source§

fn from(value: Params) -> Self

Converts to this type from the input type.
Source§

impl From<Params> for i64

Converts Params to i64.

§Panics

Panics if the Params variant is not Params::Integer.

Source§

fn from(value: Params) -> Self

Converts to this type from the input type.
Source§

impl<'a> GTVParams for Params

Source§

fn to_writer(&self, writer: &mut Writer<'_>) -> WriteResult

Source§

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§

fn into(self) -> BTreeMap<String, Params>

Converts this type into the (usually inferred) input type.
Source§

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

Source§

fn into(self) -> Vec<Params>

Converts this type into the (usually inferred) input type.
Source§

impl PartialEq for Params

Source§

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

Auto Trait Implementations§

§

impl Freeze for Params

§

impl RefUnwindSafe for Params

§

impl Send for Params

§

impl Sync for Params

§

impl Unpin for Params

§

impl UnwindSafe for Params

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T