pub trait ToRpcParams {
    // Required method
    fn to_rpc_params(self) -> Result<Option<Box<RawValue>>, Error>;
}
Expand description

Marker trait for types that can be serialized as JSON compatible strings.

This trait ensures the correctness of the RPC parameters.

Note

Please consider using the crate::params::ArrayParams and crate::params::ObjectParams than implementing this trait.

Examples

Implementation for hard-coded strings

use jsonrpsee_core::traits::ToRpcParams;
use serde_json::value::RawValue;
use jsonrpsee_core::Error;

struct ManualParam;

impl ToRpcParams for ManualParam {
    fn to_rpc_params(self) -> Result<Option<Box<RawValue>>, Error> {
        // Manually define a valid JSONRPC parameter.
        RawValue::from_string("[1, \"2\", 3]".to_string()).map(Some).map_err(Error::ParseError)
    }
}

Implementation for JSON serializable structures

use jsonrpsee_core::traits::ToRpcParams;
use serde_json::value::RawValue;
use serde::Serialize;
use jsonrpsee_core::Error;

#[derive(Serialize)]
struct SerParam {
    param_1: u8,
    param_2: String,
};

impl ToRpcParams for SerParam {
    fn to_rpc_params(self) -> Result<Option<Box<RawValue>>, Error> {
        let s = String::from_utf8(serde_json::to_vec(&self)?).expect("Valid UTF8 format");
        RawValue::from_string(s).map(Some).map_err(Error::ParseError)
    }
}

Required Methods§

source

fn to_rpc_params(self) -> Result<Option<Box<RawValue>>, Error>

Consume and serialize the type as a JSON raw value.

Implementations on Foreign Types§

source§

impl<T0: Serialize> ToRpcParams for (T0,)

source§

impl<T0: Serialize, T1: Serialize, T2: Serialize, T3: Serialize, T4: Serialize, T5: Serialize, T6: Serialize, T7: Serialize, T8: Serialize, T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize, T13: Serialize, T14: Serialize, T15: Serialize> ToRpcParams for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)

source§

impl<T0: Serialize, T1: Serialize, T2: Serialize, T3: Serialize> ToRpcParams for (T0, T1, T2, T3)

source§

impl<P, const N: usize> ToRpcParams for [P; N]where [P; N]: Serialize,

source§

impl<T0: Serialize, T1: Serialize, T2: Serialize, T3: Serialize, T4: Serialize, T5: Serialize, T6: Serialize, T7: Serialize, T8: Serialize, T9: Serialize, T10: Serialize, T11: Serialize> ToRpcParams for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)

source§

impl<T0: Serialize, T1: Serialize, T2: Serialize> ToRpcParams for (T0, T1, T2)

source§

impl<P: Serialize> ToRpcParams for &[P]

source§

impl<T0: Serialize, T1: Serialize, T2: Serialize, T3: Serialize, T4: Serialize, T5: Serialize, T6: Serialize, T7: Serialize, T8: Serialize, T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize, T13: Serialize> ToRpcParams for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)

source§

impl<T0: Serialize, T1: Serialize, T2: Serialize, T3: Serialize, T4: Serialize, T5: Serialize, T6: Serialize, T7: Serialize, T8: Serialize, T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize, T13: Serialize, T14: Serialize> ToRpcParams for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)

source§

impl<T0: Serialize, T1: Serialize, T2: Serialize, T3: Serialize, T4: Serialize, T5: Serialize, T6: Serialize, T7: Serialize, T8: Serialize, T9: Serialize, T10: Serialize> ToRpcParams for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)

source§

impl<T0: Serialize, T1: Serialize, T2: Serialize, T3: Serialize, T4: Serialize, T5: Serialize, T6: Serialize, T7: Serialize, T8: Serialize, T9: Serialize> ToRpcParams for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)

source§

impl<T0: Serialize, T1: Serialize, T2: Serialize, T3: Serialize, T4: Serialize, T5: Serialize, T6: Serialize, T7: Serialize, T8: Serialize> ToRpcParams for (T0, T1, T2, T3, T4, T5, T6, T7, T8)

source§

impl<T0: Serialize, T1: Serialize, T2: Serialize, T3: Serialize, T4: Serialize> ToRpcParams for (T0, T1, T2, T3, T4)

source§

impl<P: Serialize> ToRpcParams for Vec<P>

source§

impl<T0: Serialize, T1: Serialize, T2: Serialize, T3: Serialize, T4: Serialize, T5: Serialize, T6: Serialize, T7: Serialize> ToRpcParams for (T0, T1, T2, T3, T4, T5, T6, T7)

source§

impl<T0: Serialize, T1: Serialize, T2: Serialize, T3: Serialize, T4: Serialize, T5: Serialize> ToRpcParams for (T0, T1, T2, T3, T4, T5)

source§

impl<T0: Serialize, T1: Serialize, T2: Serialize, T3: Serialize, T4: Serialize, T5: Serialize, T6: Serialize, T7: Serialize, T8: Serialize, T9: Serialize, T10: Serialize, T11: Serialize, T12: Serialize> ToRpcParams for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)

source§

impl<T0: Serialize, T1: Serialize> ToRpcParams for (T0, T1)

source§

impl<T0: Serialize, T1: Serialize, T2: Serialize, T3: Serialize, T4: Serialize, T5: Serialize, T6: Serialize> ToRpcParams for (T0, T1, T2, T3, T4, T5, T6)

Implementors§