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_rs::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_rs::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_rs::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_rs::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 (const: unstable) · 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 UnsafeUnpin for ChainIdPattern
impl UnwindSafe for ChainIdPattern
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<'de, T> BorrowedRpcObject<'de> for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<'de, T> RpcBorrow<'de> for T
impl<T> RpcObject for T
impl<T> RpcRecv for T
impl<T> RpcSend for T
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.