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>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl JsonSchema for Addr
impl JsonSchema for Addr
sourcefn schema_name() -> String
fn schema_name() -> String
The name of the generated JSON Schema. Read more
sourcefn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
sourcefn is_referenceable() -> bool
fn is_referenceable() -> bool
Whether JSON Schemas generated for this type should be re-used where possible using the $ref
keyword. Read more
sourceimpl Ord for Addr
impl Ord for Addr
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>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Eq for Addr
impl StructuralEq for Addr
impl StructuralPartialEq for Addr
Auto Trait Implementations
impl RefUnwindSafe for Addr
impl Send for Addr
impl Sync for Addr
impl Unpin for Addr
impl UnwindSafe for Addr
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more