pub enum ChainIdPattern {
Wildcard {
namespace: String,
},
Exact {
namespace: String,
reference: String,
},
Set {
namespace: String,
references: HashSet<String>,
},
}Expand description
A pattern for matching chain IDs.
Chain ID patterns allow flexible matching of blockchain networks:
- Wildcard: Matches any chain within a namespace (e.g.,
eip155:*matches all EVM chains) - Exact: Matches a specific chain (e.g.,
eip155:8453matches only Base) - Set: Matches any chain from a set (e.g.,
eip155:{1,8453,137}matches Ethereum, Base, or Polygon)
§Serialization
Patterns serialize to human-readable strings:
- Wildcard:
"eip155:*" - Exact:
"eip155:8453" - Set:
"eip155:{1,8453,137}"
§Example
use x402_types::chain::{ChainId, ChainIdPattern};
// Match all EVM chains
let all_evm = ChainIdPattern::wildcard("eip155");
assert!(all_evm.matches(&ChainId::new("eip155", "8453")));
assert!(all_evm.matches(&ChainId::new("eip155", "137")));
assert!(!all_evm.matches(&ChainId::new("solana", "mainnet")));
// Match specific chain
let base_only = ChainIdPattern::exact("eip155", "8453");
assert!(base_only.matches(&ChainId::new("eip155", "8453")));
assert!(!base_only.matches(&ChainId::new("eip155", "137")));Variants§
Wildcard
Matches any chain within the specified namespace.
Exact
Matches exactly one specific chain.
Set
Matches any chain from a set of references within a namespace.
Implementations§
Source§impl ChainIdPattern
impl ChainIdPattern
Sourcepub fn wildcard<S: Into<String>>(namespace: S) -> Self
pub fn wildcard<S: Into<String>>(namespace: S) -> Self
Creates a wildcard pattern that matches any chain in the given namespace.
§Example
use x402_types::chain::{ChainId, ChainIdPattern};
let pattern = ChainIdPattern::wildcard("eip155");
assert!(pattern.matches(&ChainId::new("eip155", "1")));
assert!(pattern.matches(&ChainId::new("eip155", "8453")));Sourcepub fn exact<N: Into<String>, R: Into<String>>(
namespace: N,
reference: R,
) -> Self
pub fn exact<N: Into<String>, R: Into<String>>( namespace: N, reference: R, ) -> Self
Creates an exact pattern that matches only the specified chain.
§Example
use x402_types::chain::{ChainId, ChainIdPattern};
let pattern = ChainIdPattern::exact("eip155", "8453");
assert!(pattern.matches(&ChainId::new("eip155", "8453")));
assert!(!pattern.matches(&ChainId::new("eip155", "137")));Sourcepub fn set<N: Into<String>>(namespace: N, references: HashSet<String>) -> Self
pub fn set<N: Into<String>>(namespace: N, references: HashSet<String>) -> Self
Creates a set pattern that matches any chain from the given set of references.
§Example
use x402_types::chain::{ChainId, ChainIdPattern};
use std::collections::HashSet;
let refs: HashSet<String> = ["1", "8453", "137"].iter().map(|s| s.to_string()).collect();
let pattern = ChainIdPattern::set("eip155", refs);
assert!(pattern.matches(&ChainId::new("eip155", "8453")));
assert!(!pattern.matches(&ChainId::new("eip155", "42")));Trait Implementations§
Source§impl Clone for ChainIdPattern
impl Clone for ChainIdPattern
Source§fn clone(&self) -> ChainIdPattern
fn clone(&self) -> ChainIdPattern
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ChainIdPattern
impl Debug for ChainIdPattern
Source§impl<'de> Deserialize<'de> for ChainIdPattern
impl<'de> Deserialize<'de> for ChainIdPattern
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for ChainIdPattern
impl Display for ChainIdPattern
Source§impl From<ChainId> for ChainIdPattern
impl From<ChainId> for ChainIdPattern
Source§impl From<ChainIdPattern> for Vec<ChainIdPattern>
impl From<ChainIdPattern> for Vec<ChainIdPattern>
Source§fn from(value: ChainIdPattern) -> Self
fn from(value: ChainIdPattern) -> Self
Converts to this type from the input type.
Source§impl FromStr for ChainIdPattern
impl FromStr for ChainIdPattern
Auto Trait Implementations§
impl Freeze for ChainIdPattern
impl RefUnwindSafe for ChainIdPattern
impl Send for ChainIdPattern
impl Sync for ChainIdPattern
impl Unpin for ChainIdPattern
impl UnwindSafe for ChainIdPattern
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