Skip to main content

TypedAddress

Struct TypedAddress 

Source
pub struct TypedAddress<T> { /* private fields */ }
Expand description

A 32-byte public key tagged with a phantom layout type.

Zero-cost: #[repr(transparent)] over [u8; 32], align 1. The type parameter T exists only at compile time for type safety – it has no runtime representation.

Implementations§

Source§

impl<T> TypedAddress<T>

Source

pub const fn new(bytes: [u8; 32]) -> TypedAddress<T>

Create a typed address from raw bytes.

Source

pub fn from_slice(slice: &[u8; 32]) -> TypedAddress<T>

Create from a byte slice reference (copies 32 bytes).

Source

pub fn from_account(account: &AccountView) -> TypedAddress<T>

Create from an AccountView’s address.

Source

pub const fn zeroed() -> TypedAddress<T>

The zero address (all bytes 0).

Source

pub const fn as_bytes(&self) -> &[u8; 32]

Raw 32-byte key.

Source

pub fn eq_bytes(&self, other: &[u8; 32]) -> bool

Check if this address equals a raw 32-byte key.

Source

pub fn eq_account(&self, account: &AccountView) -> bool

Check if this address matches an AccountView’s address.

Source

pub fn require_eq_account( &self, account: &AccountView, ) -> Result<(), ProgramError>

Verify this address matches the given account, returning an error if not.

Source

pub fn is_zero(&self) -> bool

Check if this is the zero address.

Source

pub const fn cast<U>(self) -> TypedAddress<U>

Cast this typed address to a different type.

Use sparingly – this exists for interop with legacy/untyped code.

Source

pub const fn untyped(self) -> UntypedAddress

Erase the type tag, returning an untyped address.

Trait Implementations§

Source§

impl<T> AsRef<[u8]> for TypedAddress<T>

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> AsRef<[u8; 32]> for TypedAddress<T>

Source§

fn as_ref(&self) -> &[u8; 32]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> Clone for TypedAddress<T>

Source§

fn clone(&self) -> TypedAddress<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for TypedAddress<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> FixedLayout for TypedAddress<T>

Source§

const SIZE: usize = 32

Total byte size on the wire (including any header if applicable).
Source§

impl<T> From<[u8; 32]> for TypedAddress<T>

Source§

fn from(bytes: [u8; 32]) -> TypedAddress<T>

Converts to this type from the input type.
Source§

impl<T> PartialEq<[u8; 32]> for TypedAddress<T>

Source§

fn eq(&self, other: &[u8; 32]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialEq for TypedAddress<T>

Source§

fn eq(&self, other: &TypedAddress<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Zeroable for TypedAddress<T>
where T: 'static,

Available on crate feature hopper-native-backend only.
Source§

fn zeroed() -> Self

Source§

impl<T> Copy for TypedAddress<T>

Source§

impl<T> Eq for TypedAddress<T>

Source§

impl<T> Pod for TypedAddress<T>
where T: Copy + 'static,

Available on crate feature hopper-native-backend only.
Source§

impl<T> Pod for TypedAddress<T>
where T: Copy + 'static,

Auto Trait Implementations§

§

impl<T> Freeze for TypedAddress<T>

§

impl<T> RefUnwindSafe for TypedAddress<T>
where T: RefUnwindSafe,

§

impl<T> Send for TypedAddress<T>
where T: Send,

§

impl<T> Sync for TypedAddress<T>
where T: Sync,

§

impl<T> Unpin for TypedAddress<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for TypedAddress<T>

§

impl<T> UnwindSafe for TypedAddress<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
Source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WireLayout for T
where T: ZeroCopy,

Source§

const WIRE_SIZE: usize = _

Size of the on-wire representation, in bytes.
Source§

impl<T> AnyBitPattern for T
where T: Pod,

Source§

impl<T> NoUninit for T
where T: Pod,

Source§

impl<T> ZeroCopy for T
where T: Pod + 'static + HopperZeroCopySealed,