Struct nym_mixnet_contract_common::Addr
source · pub struct Addr(_);
Expand description
A human readable address.
In Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.
This type represents a validated address. It can be created in the following ways
- Use
Addr::unchecked(input)
- Use
let checked: Addr = deps.api.addr_validate(input)?
- Use
let checked: Addr = deps.api.addr_humanize(canonical_addr)?
- Deserialize from JSON. This must only be done from JSON that was validated before
such as a contract’s state.
Addr
must not be used in messages sent by the user because this would result in unvalidated instances.
This type is immutable. If you really need to mutate it (Really? Are you sure?), create
a mutable copy using let mut mutable = Addr::to_string()
and operate on that String
instance.
Implementations§
source§impl Addr
impl Addr
sourcepub fn unchecked(input: impl Into<String>) -> Addr
pub fn unchecked(input: impl Into<String>) -> Addr
Creates a new Addr
instance from the given input without checking the validity
of the input. Since Addr
must always contain valid addresses, the caller is
responsible for ensuring the input is valid.
Use this in cases where the address was validated before or in test code.
If you see this in contract code, it should most likely be replaced with
let checked: Addr = deps.api.addr_humanize(canonical_addr)?
.
Examples
let address = Addr::unchecked("foobar");
assert_eq!(address, "foobar");
pub fn as_str(&self) -> &str
sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Returns the UTF-8 encoded address string as a byte array.
This is equivalent to address.as_str().as_bytes()
.
sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Utility for explicit conversion to String
.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Addr
impl<'de> Deserialize<'de> for Addr
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<Addr, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>( __deserializer: __D ) -> Result<Addr, <__D as Deserializer<'de>>::Error>where __D: Deserializer<'de>,
source§impl JsonSchema for Addr
impl JsonSchema for Addr
source§fn schema_name() -> String
fn schema_name() -> String
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read moresource§impl Ord for Addr
impl Ord for Addr
source§impl PartialEq<Addr> for Addr
impl PartialEq<Addr> for Addr
source§impl PartialEq<String> for Addr
impl PartialEq<String> for Addr
Implement Addr == String
source§impl PartialOrd<Addr> for Addr
impl PartialOrd<Addr> for Addr
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more