program::message::AccountKeys: `Clone`, `Default`, `Debug`, `Eq` (#33749)

It is a pretty standard set of traits to implement on most types.  Both `Pubkey`
and `LoadedAddresses` contained within the `AccountKeys` already implement them.
Doing the same for `AccountKeys` could simplify unit tests and/or some common
value manipulation logic.
This commit is contained in:
Illia Bobyr 2023-10-18 10:22:33 -07:00 committed by GitHub
parent e96678b302
commit 84c2f9de55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -4,11 +4,12 @@ use {
message::{v0::LoadedAddresses, CompileError},
pubkey::Pubkey,
},
std::{collections::BTreeMap, ops::Index},
std::{collections::BTreeMap, iter::zip, ops::Index},
};
/// Collection of static and dynamically loaded keys used to load accounts
/// during transaction processing.
#[derive(Clone, Default, Debug, Eq)]
pub struct AccountKeys<'a> {
static_keys: &'a [Pubkey],
dynamic_keys: Option<&'a LoadedAddresses>,
@ -138,6 +139,12 @@ impl<'a> AccountKeys<'a> {
}
}
impl PartialEq for AccountKeys<'_> {
fn eq(&self, other: &Self) -> bool {
zip(self.iter(), other.iter()).all(|(a, b)| a == b)
}
}
#[cfg(test)]
mod tests {
use {super::*, crate::instruction::AccountMeta};