Struct cosmwasm_std::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
sourceimpl 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]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [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
sourceimpl<'de> Deserialize<'de> for Addr
impl<'de> Deserialize<'de> for Addr
sourcefn 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>,
sourceimpl JsonSchema for Addr
impl JsonSchema for Addr
sourcefn schema_name() -> String
fn schema_name() -> String
sourcefn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
sourcefn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read moresourceimpl Ord for Addr
impl Ord for Addr
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
sourceimpl PartialEq<Addr> for String
impl PartialEq<Addr> for String
Implement String == Addr
sourceimpl PartialEq<String> for Addr
impl PartialEq<String> for Addr
Implement Addr == String
sourceimpl PartialOrd<Addr> for Addr
impl PartialOrd<Addr> for Addr
sourcefn partial_cmp(&self, other: &Addr) -> Option<Ordering>
fn partial_cmp(&self, other: &Addr) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more