Struct cosmwasm_std::Addr [−][src]
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
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");
Returns the UTF-8 encoded address string as a byte array.
This is equivalent to address.as_str().as_bytes()
.
Utility for explicit conversion to String
.
Trait Implementations
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
Implement Addr == &str
Implement &str == Addr
Implement String == Addr
Implement Addr == String
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for Addr
impl UnwindSafe for Addr
Blanket Implementations
Mutably borrows from an owned value. Read more