pub struct ChainRegistry<P>(/* private fields */);Expand description
Registry of configured chain providers indexed by chain ID.
The registry is built from configuration and provides lookup methods for finding providers by exact chain ID or by pattern matching.
§Type Parameters
P- The chain provider type (e.g., [ChainProvider] or a custom provider type)
§Example
ⓘ
use x402_rs::chain::{ChainRegistry, ChainIdPattern, ChainProvider};
use x402_rs::config::Config;
let config = Config::load()?;
let registry = ChainRegistry::from_config(config.chains()).await?;
// Find provider for a specific chain
let base_provider = registry.by_chain_id(ChainId::new("eip155", "8453"));
// Find provider matching a pattern
let any_evm = registry.by_chain_id_pattern(&ChainIdPattern::wildcard("eip155"));Implementations§
Source§impl<P> ChainRegistry<P>
impl<P> ChainRegistry<P>
Sourcepub fn by_chain_id(&self, chain_id: ChainId) -> Option<&P>
pub fn by_chain_id(&self, chain_id: ChainId) -> Option<&P>
Looks up a provider by exact chain ID.
Returns None if no provider is configured for the given chain.
Sourcepub fn by_chain_id_pattern(&self, pattern: &ChainIdPattern) -> Vec<&P>
pub fn by_chain_id_pattern(&self, pattern: &ChainIdPattern) -> Vec<&P>
Looks up providers by chain ID pattern matching.
Returns all providers whose chain IDs match the given pattern. The pattern can be:
- Wildcard: Matches any chain within a namespace (e.g.,
eip155:*) - Exact: Matches a specific chain (e.g.,
eip155:8453) - Set: Matches any chain from a set of references (e.g.,
eip155:{1,8453,137})
§Example
ⓘ
use x402_rs::chain::{ChainRegistry, ChainIdPattern};
use x402_rs::config::Config;
let config = Config::load()?;
let registry = ChainRegistry::from_config(config.chains()).await?;
// Find all EVM chain providers
let evm_providers = registry.by_chain_id_pattern(&ChainIdPattern::wildcard("eip155"));
assert!(!evm_providers.is_empty());
// Find providers for specific chains
let mainnet_chains = ChainIdPattern::set("eip155", ["1", "8453", "137"].into_iter().map(String::from).collect());
let mainnet_providers = registry.by_chain_id_pattern(&mainnet_chains);Trait Implementations§
Auto Trait Implementations§
impl<P> Freeze for ChainRegistry<P>
impl<P> RefUnwindSafe for ChainRegistry<P>where
P: RefUnwindSafe,
impl<P> Send for ChainRegistry<P>where
P: Send,
impl<P> Sync for ChainRegistry<P>where
P: Sync,
impl<P> Unpin for ChainRegistry<P>where
P: Unpin,
impl<P> UnwindSafe for ChainRegistry<P>where
P: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more