pub fn deserialize_rpc_urls<'de, D>(
deserializer: D,
) -> Result<Option<Vec<RpcConfig>>, D::Error>where
D: Deserializer<'de>,Expand description
Custom deserializer for Option<Vec<RpcConfig>> that supports multiple input formats.
This function is designed to be used with #[serde(deserialize_with = "...")] and supports:
-
Simple format: Array of strings, e.g.,
["https://rpc1.com", "https://rpc2.com"]Each string is converted to anRpcConfigwith default weight (100). -
Extended format: Array of objects, e.g.,
[{"url": "https://rpc.com", "weight": 50}]Each object is deserialized directly as anRpcConfig. -
Mixed format: Array containing both strings and objects e.g.,
["https://rpc1.com", {"url": "https://rpc2.com", "weight": 50}]
§Example Usage
ⓘ
use serde::Deserialize;
use openzeppelin_relayer::models::relayer::{RpcConfig, deserialize_rpc_urls};
#[derive(Deserialize)]
struct MyConfig {
#[serde(default, deserialize_with = "deserialize_rpc_urls")]
rpc_urls: Option<Vec<RpcConfig>>,
}