From ddda94e4868b487c25a81c22be03472921b48567 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sun, 15 Aug 2021 16:21:04 +0000 Subject: [PATCH] Add AsRef for AccountInfo (backport #19235) (#19238) * Add AsRef for AccountInfo (cherry picked from commit 930465e67c063f2e07599e29b0d78d5894332f81) * add test for AsRef (cherry picked from commit d10e37a8293a0bc5331cb5c3bda600963c8e5a62) Co-authored-by: Kirill Fomichev --- sdk/program/src/account_info.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sdk/program/src/account_info.rs b/sdk/program/src/account_info.rs index 1a49578eac..084e08c807 100644 --- a/sdk/program/src/account_info.rs +++ b/sdk/program/src/account_info.rs @@ -220,6 +220,12 @@ pub fn next_account_infos<'a, 'b: 'a>( Ok(accounts) } +impl<'a> AsRef> 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); + } }