ss58_registry/
registry.rsuse super::*;
include!(concat!(env!("OUT_DIR"), "/registry_gen.rs"));
#[cfg(feature = "std")]
impl std::fmt::Display for Ss58AddressFormatRegistry {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let lookup = PREFIX_TO_INDEX
.binary_search_by_key(&from_known_address_format(*self), |(prefix, _)| *prefix)
.expect("always be found");
let (_, idx) = PREFIX_TO_INDEX[lookup];
write!(f, "{}", ALL_SS58_ADDRESS_FORMAT_NAMES[idx])
}
}
impl TryFrom<Ss58AddressFormat> for Ss58AddressFormatRegistry {
type Error = ParseError;
fn try_from(x: Ss58AddressFormat) -> Result<Ss58AddressFormatRegistry, ParseError> {
PREFIX_TO_INDEX
.binary_search_by_key(&x.prefix(), |(prefix, _)| *prefix)
.map(|lookup| {
let (_, idx) = PREFIX_TO_INDEX[lookup];
ALL_SS58_ADDRESS_FORMATS[idx]
})
.map_err(|_| ParseError)
}
}
pub const fn from_known_address_format(x: Ss58AddressFormatRegistry) -> u16 {
x as u16
}
impl core::fmt::Debug for TokenRegistry {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let token: Token = (*self).into();
f.debug_struct("TokenRegistry")
.field("name", &token.name)
.field("decimals", &token.decimals)
.finish()
}
}