pub struct Payload { /* private fields */ }Expand description
A wrapper type for the payload hashmap.
Implementations§
Source§impl Payload
impl Payload
Sourcepub fn from<const N: usize>(arr: [(String, PayloadType); N]) -> Self
pub fn from<const N: usize>(arr: [(String, PayloadType); N]) -> Self
Create a Payload from an array of key-value pairs, specified as
(PayloadKey, PayloadType) tuples.
Sourcepub fn insert(&mut self, key: String, value: PayloadType) -> Option<PayloadType>
pub fn insert(&mut self, key: String, value: PayloadType) -> Option<PayloadType>
Inserts a key-value pair into the Payload. If the Payload did not have this key
present, then None is returned. If the Payload did have this key present, the value
is updated, and the old value is returned. The key is not updated, though; this matters
for types that can be == without being identical. See std::collections::HashMap
documentation for more info.
Sourcepub fn try_insert(&mut self, key: String, value: PayloadType) -> ProgramResult
pub fn try_insert(&mut self, key: String, value: PayloadType) -> ProgramResult
Tries to insert a key-value pair into a Payload. If this key is already in the Payload
nothing is updated and an error is returned.
Sourcepub fn get(&self, key: &String) -> Option<&PayloadType>
pub fn get(&self, key: &String) -> Option<&PayloadType>
Returns a reference to the value corresponding to the key.
Sourcepub fn get_pubkey(&self, key: &String) -> Option<&Pubkey>
pub fn get_pubkey(&self, key: &String) -> Option<&Pubkey>
Get a reference to the Pubkey associated with a key, if and only if the Payload value
is the PayloadType::Pubkey variant. Returns None if the key is not present in the
Payload or the value is a different PayloadType variant.
Sourcepub fn get_seeds(&self, key: &String) -> Option<&SeedsVec>
pub fn get_seeds(&self, key: &String) -> Option<&SeedsVec>
Get a reference to the SeedsVec associated with a key, if and only if the Payload value
is the PayloadType::Seeds variant. Returns None if the key is not present in the
Payload or the value is a different PayloadType variant.
Sourcepub fn get_merkle_proof(&self, key: &String) -> Option<&ProofInfo>
pub fn get_merkle_proof(&self, key: &String) -> Option<&ProofInfo>
Get a reference to the ProofInfo associated with a key, if and only if the Payload value
is the PayloadType::MerkleProof variant. Returns None if the key is not present in the
Payload or the value is a different PayloadType variant.
Sourcepub fn get_amount(&self, key: &String) -> Option<u64>
pub fn get_amount(&self, key: &String) -> Option<u64>
Get the u64 associated with a key, if and only if the Payload value is the
PayloadType::Number variant. Returns None if the key is not present in the Payload
or the value is a different PayloadType variant.
Trait Implementations§
Source§impl BorshDeserialize for Payload
impl BorshDeserialize for Payload
fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self, Error>
Source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
Source§impl BorshSerialize for Payload
impl BorshSerialize for Payload
Source§impl<'de> Deserialize<'de> for Payload
impl<'de> Deserialize<'de> for Payload
Source§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>,
impl Eq for Payload
impl StructuralPartialEq for Payload
Auto Trait Implementations§
impl Freeze for Payload
impl RefUnwindSafe for Payload
impl Send for Payload
impl Sync for Payload
impl Unpin for Payload
impl UnwindSafe for Payload
Blanket Implementations§
Source§impl<T> AbiEnumVisitor for T
impl<T> AbiEnumVisitor for T
default fn visit_for_abi( &self, _digester: &mut AbiDigester, ) -> Result<AbiDigester, DigestError>
Source§impl<T> AbiEnumVisitor for T
impl<T> AbiEnumVisitor for T
default fn visit_for_abi( &self, digester: &mut AbiDigester, ) -> Result<AbiDigester, DigestError>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more