Add AsRef<AccountInfo> for AccountInfo (backport #19235) (#19238)

* Add AsRef<AccountInfo> for AccountInfo

(cherry picked from commit 930465e67c)

* add test for AsRef

(cherry picked from commit d10e37a829)

Co-authored-by: Kirill Fomichev <fanatid@ya.ru>
This commit is contained in:
mergify[bot]
2021-08-15 16:21:04 +00:00
committed by GitHub
parent 73ed9f56d7
commit ddda94e486

View File

@ -220,6 +220,12 @@ pub fn next_account_infos<'a, 'b: 'a>(
Ok(accounts)
}
impl<'a> AsRef<AccountInfo<'a>> for AccountInfo<'a> {
fn as_ref(&self) -> &AccountInfo<'a> {
self
}
}
#[cfg(test)]
mod tests {
use super::*;
@ -260,4 +266,13 @@ mod tests {
assert_eq!(k4, *info2_3_4[2].key);
assert_eq!(k5, *info5.key);
}
#[test]
fn test_account_info_as_ref() {
let k = Pubkey::new_unique();
let l = &mut 0;
let d = &mut [0u8];
let info = AccountInfo::new(&k, false, false, l, d, &k, false, 0);
assert_eq!(info.key, info.as_ref().key);
}
}