pub enum PoolIdentifier {
Address(Ustr),
PoolId(Ustr),
}Expand description
Protocol-aware pool identifier for DeFi liquidity pools.
This enum distinguishes between two types of pool identifiers:
- Address: Used by V2/V3 protocols where pool identifier equals pool contract address (42 chars: “0x” + 40 hex)
- PoolId: Used by V4 protocols where pool identifier is a bytes32 hash (66 chars: “0x” + 64 hex)
The type implements case-insensitive equality and hashing for address comparison, while preserving the original case for display purposes.
Variants§
Address(Ustr)
V2/V3 pool identifier (checksummed Ethereum address)
PoolId(Ustr)
V4 pool identifier (32-byte pool ID as hex string)
Implementations§
Source§impl PoolIdentifier
impl PoolIdentifier
Sourcepub fn new_checked<T: AsRef<str>>(value: T) -> Result<Self>
pub fn new_checked<T: AsRef<str>>(value: T) -> Result<Self>
Creates a new PoolIdentifier instance with correctness checking.
Automatically detects variant based on string length:
- 42 characters (0x + 40 hex): Address variant
- 66 characters (0x + 64 hex): PoolId variant
§Errors
Returns an error if:
- String doesn’t start with “0x”
- Length is neither 42 nor 66 characters
- Contains invalid hex characters
- Address checksum validation fails (for Address variant)
Sourcepub fn from_address(address: Address) -> Self
pub fn from_address(address: Address) -> Self
Creates an Address variant from an alloy Address.
Returns the checksummed representation.
Sourcepub fn from_pool_id_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_pool_id_bytes(bytes: &[u8]) -> Result<Self>
Creates a PoolId variant from raw bytes (32 bytes).
§Errors
Returns an error if bytes length is not 32.
Sourcepub fn from_pool_id_hex<T: AsRef<str>>(hex: T) -> Result<Self>
pub fn from_pool_id_hex<T: AsRef<str>>(hex: T) -> Result<Self>
Creates a PoolId variant from a hex string (with or without 0x prefix).
§Errors
Returns an error if the string is not valid 64-character hex.
Sourcepub fn is_address(&self) -> bool
pub fn is_address(&self) -> bool
Returns true if this is an Address variant (V2/V3 pools).
Sourcepub fn is_pool_id(&self) -> bool
pub fn is_pool_id(&self) -> bool
Returns true if this is a PoolId variant (V4 pools).
Sourcepub fn to_address(&self) -> Result<Address>
pub fn to_address(&self) -> Result<Address>
Converts to native Address type (V2/V3 pools only).
Returns the underlying Address for use with alloy/ethers operations.
§Errors
Returns error if this is a PoolId variant or if parsing fails.
Trait Implementations§
Source§impl AsRef<str> for PoolIdentifier
impl AsRef<str> for PoolIdentifier
Source§impl Clone for PoolIdentifier
impl Clone for PoolIdentifier
Source§fn clone(&self) -> PoolIdentifier
fn clone(&self) -> PoolIdentifier
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PoolIdentifier
impl Debug for PoolIdentifier
Source§impl<'de> Deserialize<'de> for PoolIdentifier
impl<'de> Deserialize<'de> for PoolIdentifier
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>,
Source§impl Display for PoolIdentifier
impl Display for PoolIdentifier
Source§impl From<&str> for PoolIdentifier
impl From<&str> for PoolIdentifier
Source§impl From<String> for PoolIdentifier
impl From<String> for PoolIdentifier
Source§impl FromStr for PoolIdentifier
impl FromStr for PoolIdentifier
Source§impl Hash for PoolIdentifier
impl Hash for PoolIdentifier
Source§impl Ord for PoolIdentifier
impl Ord for PoolIdentifier
Source§impl PartialEq for PoolIdentifier
impl PartialEq for PoolIdentifier
Source§impl PartialOrd for PoolIdentifier
impl PartialOrd for PoolIdentifier
Source§impl Serialize for PoolIdentifier
impl Serialize for PoolIdentifier
impl Copy for PoolIdentifier
impl Eq for PoolIdentifier
Auto Trait Implementations§
impl Freeze for PoolIdentifier
impl RefUnwindSafe for PoolIdentifier
impl Send for PoolIdentifier
impl Sync for PoolIdentifier
impl Unpin for PoolIdentifier
impl UnwindSafe for PoolIdentifier
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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>
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> Separable for Twhere
T: Display,
impl<T> Separable for Twhere
T: Display,
Source§fn separate_by_policy(&self, policy: SeparatorPolicy<'_>) -> String
fn separate_by_policy(&self, policy: SeparatorPolicy<'_>) -> String
SeparatorPolicy. Read more