Browse Source

lang: mut types using blanket implementations (#1127)

Paul 3 years ago
parent
commit
8739db4e58

+ 0 - 14
lang/src/accounts/account.rs

@@ -369,14 +369,6 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Owner + Clone> ToAccountI
     }
     }
 }
 }
 
 
-impl<'info, T: AccountSerialize + AccountDeserialize + Owner + Clone> ToAccountInfo<'info>
-    for Account<'info, T>
-{
-    fn to_account_info(&self) -> AccountInfo<'info> {
-        self.info.clone()
-    }
-}
-
 impl<'info, T: AccountSerialize + AccountDeserialize + Owner + Clone> AsRef<AccountInfo<'info>>
 impl<'info, T: AccountSerialize + AccountDeserialize + Owner + Clone> AsRef<AccountInfo<'info>>
     for Account<'info, T>
     for Account<'info, T>
 {
 {
@@ -411,9 +403,3 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Owner + Clone> DerefMut for
         &mut self.account
         &mut self.account
     }
     }
 }
 }
-
-impl<'info, T: AccountSerialize + AccountDeserialize + Owner + Clone> Key for Account<'info, T> {
-    fn key(&self) -> Pubkey {
-        *self.info.key
-    }
-}

+ 2 - 20
lang/src/accounts/account_info.rs

@@ -3,9 +3,8 @@
 //! should be used instead.
 //! should be used instead.
 
 
 use crate::error::ErrorCode;
 use crate::error::ErrorCode;
-use crate::{Accounts, AccountsExit, Key, ToAccountInfo, ToAccountInfos, ToAccountMetas};
+use crate::{Accounts, AccountsExit, ToAccountInfos, ToAccountMetas};
 use solana_program::account_info::AccountInfo;
 use solana_program::account_info::AccountInfo;
-use solana_program::entrypoint::ProgramResult;
 use solana_program::instruction::AccountMeta;
 use solana_program::instruction::AccountMeta;
 use solana_program::program_error::ProgramError;
 use solana_program::program_error::ProgramError;
 use solana_program::pubkey::Pubkey;
 use solana_program::pubkey::Pubkey;
@@ -42,21 +41,4 @@ impl<'info> ToAccountInfos<'info> for AccountInfo<'info> {
     }
     }
 }
 }
 
 
-impl<'info> ToAccountInfo<'info> for AccountInfo<'info> {
-    fn to_account_info(&self) -> AccountInfo<'info> {
-        self.clone()
-    }
-}
-
-impl<'info> AccountsExit<'info> for AccountInfo<'info> {
-    fn exit(&self, _program_id: &Pubkey) -> ProgramResult {
-        // no-op
-        Ok(())
-    }
-}
-
-impl<'info> Key for AccountInfo<'info> {
-    fn key(&self) -> Pubkey {
-        *self.key
-    }
-}
+impl<'info> AccountsExit<'info> for AccountInfo<'info> {}

+ 1 - 20
lang/src/accounts/cpi_account.rs

@@ -84,13 +84,6 @@ impl<'info, T: AccountDeserialize + Clone> ToAccountInfos<'info> for CpiAccount<
     }
     }
 }
 }
 
 
-#[allow(deprecated)]
-impl<'info, T: AccountDeserialize + Clone> ToAccountInfo<'info> for CpiAccount<'info, T> {
-    fn to_account_info(&self) -> AccountInfo<'info> {
-        self.info.clone()
-    }
-}
-
 #[allow(deprecated)]
 #[allow(deprecated)]
 impl<'info, T: AccountDeserialize + Clone> AsRef<AccountInfo<'info>> for CpiAccount<'info, T> {
 impl<'info, T: AccountDeserialize + Clone> AsRef<AccountInfo<'info>> for CpiAccount<'info, T> {
     fn as_ref(&self) -> &AccountInfo<'info> {
     fn as_ref(&self) -> &AccountInfo<'info> {
@@ -115,19 +108,7 @@ impl<'a, T: AccountDeserialize + Clone> DerefMut for CpiAccount<'a, T> {
 }
 }
 
 
 #[allow(deprecated)]
 #[allow(deprecated)]
-impl<'info, T: AccountDeserialize + Clone> AccountsExit<'info> for CpiAccount<'info, T> {
-    fn exit(&self, _program_id: &Pubkey) -> ProgramResult {
-        // no-op
-        Ok(())
-    }
-}
-
-#[allow(deprecated)]
-impl<'info, T: AccountDeserialize + Clone> Key for CpiAccount<'info, T> {
-    fn key(&self) -> Pubkey {
-        *self.info.key
-    }
-}
+impl<'info, T: AccountDeserialize + Clone> AccountsExit<'info> for CpiAccount<'info, T> {}
 
 
 #[allow(deprecated)]
 #[allow(deprecated)]
 impl<'info, T> From<Account<'info, T>> for CpiAccount<'info, T>
 impl<'info, T> From<Account<'info, T>> for CpiAccount<'info, T>

+ 1 - 23
lang/src/accounts/cpi_state.rs

@@ -2,11 +2,9 @@ use crate::error::ErrorCode;
 #[allow(deprecated)]
 #[allow(deprecated)]
 use crate::{accounts::state::ProgramState, context::CpiStateContext};
 use crate::{accounts::state::ProgramState, context::CpiStateContext};
 use crate::{
 use crate::{
-    AccountDeserialize, AccountSerialize, Accounts, AccountsExit, Key, ToAccountInfo,
-    ToAccountInfos, ToAccountMetas,
+    AccountDeserialize, AccountSerialize, Accounts, AccountsExit, ToAccountInfos, ToAccountMetas,
 };
 };
 use solana_program::account_info::AccountInfo;
 use solana_program::account_info::AccountInfo;
-use solana_program::entrypoint::ProgramResult;
 use solana_program::instruction::AccountMeta;
 use solana_program::instruction::AccountMeta;
 use solana_program::program_error::ProgramError;
 use solana_program::program_error::ProgramError;
 use solana_program::pubkey::Pubkey;
 use solana_program::pubkey::Pubkey;
@@ -109,15 +107,6 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountInfos<'in
     }
     }
 }
 }
 
 
-#[allow(deprecated)]
-impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountInfo<'info>
-    for CpiState<'info, T>
-{
-    fn to_account_info(&self) -> AccountInfo<'info> {
-        self.inner.info.clone()
-    }
-}
-
 #[allow(deprecated)]
 #[allow(deprecated)]
 impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AsRef<AccountInfo<'info>>
 impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AsRef<AccountInfo<'info>>
     for CpiState<'info, T>
     for CpiState<'info, T>
@@ -147,15 +136,4 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> DerefMut for CpiSt
 impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AccountsExit<'info>
 impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AccountsExit<'info>
     for CpiState<'info, T>
     for CpiState<'info, T>
 {
 {
-    fn exit(&self, _program_id: &Pubkey) -> ProgramResult {
-        // no-op
-        Ok(())
-    }
-}
-
-#[allow(deprecated)]
-impl<'info, T: AccountSerialize + AccountDeserialize + Clone> Key for CpiState<'info, T> {
-    fn key(&self) -> Pubkey {
-        *self.inner.info.key
-    }
 }
 }

+ 1 - 16
lang/src/accounts/loader.rs

@@ -1,7 +1,6 @@
 use crate::error::ErrorCode;
 use crate::error::ErrorCode;
 use crate::{
 use crate::{
-    Accounts, AccountsClose, AccountsExit, Key, ToAccountInfo, ToAccountInfos, ToAccountMetas,
-    ZeroCopy,
+    Accounts, AccountsClose, AccountsExit, ToAccountInfo, ToAccountInfos, ToAccountMetas, ZeroCopy,
 };
 };
 use arrayref::array_ref;
 use arrayref::array_ref;
 use solana_program::account_info::AccountInfo;
 use solana_program::account_info::AccountInfo;
@@ -206,17 +205,3 @@ impl<'info, T: ZeroCopy> ToAccountInfos<'info> for Loader<'info, T> {
         vec![self.acc_info.clone()]
         vec![self.acc_info.clone()]
     }
     }
 }
 }
-
-#[allow(deprecated)]
-impl<'info, T: ZeroCopy> ToAccountInfo<'info> for Loader<'info, T> {
-    fn to_account_info(&self) -> AccountInfo<'info> {
-        self.acc_info.clone()
-    }
-}
-
-#[allow(deprecated)]
-impl<'info, T: ZeroCopy> Key for Loader<'info, T> {
-    fn key(&self) -> Pubkey {
-        *self.acc_info.key
-    }
-}

+ 2 - 14
lang/src/accounts/loader_account.rs

@@ -2,8 +2,8 @@
 
 
 use crate::error::ErrorCode;
 use crate::error::ErrorCode;
 use crate::{
 use crate::{
-    Accounts, AccountsClose, AccountsExit, Key, Owner, ToAccountInfo, ToAccountInfos,
-    ToAccountMetas, ZeroCopy,
+    Accounts, AccountsClose, AccountsExit, Owner, ToAccountInfo, ToAccountInfos, ToAccountMetas,
+    ZeroCopy,
 };
 };
 use arrayref::array_ref;
 use arrayref::array_ref;
 use solana_program::account_info::AccountInfo;
 use solana_program::account_info::AccountInfo;
@@ -258,15 +258,3 @@ impl<'info, T: ZeroCopy + Owner> ToAccountInfos<'info> for AccountLoader<'info,
         vec![self.acc_info.clone()]
         vec![self.acc_info.clone()]
     }
     }
 }
 }
-
-impl<'info, T: ZeroCopy + Owner> ToAccountInfo<'info> for AccountLoader<'info, T> {
-    fn to_account_info(&self) -> AccountInfo<'info> {
-        self.acc_info.clone()
-    }
-}
-
-impl<'info, T: ZeroCopy + Owner> Key for AccountLoader<'info, T> {
-    fn key(&self) -> Pubkey {
-        *self.acc_info.key
-    }
-}

+ 1 - 12
lang/src/accounts/program.rs

@@ -162,12 +162,6 @@ impl<'info, T: Id + Clone> ToAccountInfos<'info> for Program<'info, T> {
     }
     }
 }
 }
 
 
-impl<'info, T: Id + Clone> ToAccountInfo<'info> for Program<'info, T> {
-    fn to_account_info(&self) -> AccountInfo<'info> {
-        self.info.clone()
-    }
-}
-
 impl<'info, T: Id + Clone> AsRef<AccountInfo<'info>> for Program<'info, T> {
 impl<'info, T: Id + Clone> AsRef<AccountInfo<'info>> for Program<'info, T> {
     fn as_ref(&self) -> &AccountInfo<'info> {
     fn as_ref(&self) -> &AccountInfo<'info> {
         &self.info
         &self.info
@@ -182,9 +176,4 @@ impl<'info, T: Id + Clone> Deref for Program<'info, T> {
     }
     }
 }
 }
 
 
-impl<'info, T: Id + Clone> AccountsExit<'info> for Program<'info, T> {
-    fn exit(&self, _program_id: &Pubkey) -> ProgramResult {
-        // No-op.
-        Ok(())
-    }
-}
+impl<'info, T: AccountDeserialize + Id + Clone> AccountsExit<'info> for Program<'info, T> {}

+ 2 - 18
lang/src/accounts/program_account.rs

@@ -2,8 +2,8 @@
 use crate::accounts::cpi_account::CpiAccount;
 use crate::accounts::cpi_account::CpiAccount;
 use crate::error::ErrorCode;
 use crate::error::ErrorCode;
 use crate::{
 use crate::{
-    AccountDeserialize, AccountSerialize, Accounts, AccountsClose, AccountsExit, Key,
-    ToAccountInfo, ToAccountInfos, ToAccountMetas,
+    AccountDeserialize, AccountSerialize, Accounts, AccountsClose, AccountsExit, ToAccountInfo,
+    ToAccountInfos, ToAccountMetas,
 };
 };
 use solana_program::account_info::AccountInfo;
 use solana_program::account_info::AccountInfo;
 use solana_program::entrypoint::ProgramResult;
 use solana_program::entrypoint::ProgramResult;
@@ -139,15 +139,6 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountInfos<'in
     }
     }
 }
 }
 
 
-#[allow(deprecated)]
-impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountInfo<'info>
-    for ProgramAccount<'info, T>
-{
-    fn to_account_info(&self) -> AccountInfo<'info> {
-        self.inner.info.clone()
-    }
-}
-
 #[allow(deprecated)]
 #[allow(deprecated)]
 impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AsRef<AccountInfo<'info>>
 impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AsRef<AccountInfo<'info>>
     for ProgramAccount<'info, T>
     for ProgramAccount<'info, T>
@@ -188,10 +179,3 @@ where
         Self::new(a.to_account_info(), Deref::deref(&a).clone())
         Self::new(a.to_account_info(), Deref::deref(&a).clone())
     }
     }
 }
 }
-
-#[allow(deprecated)]
-impl<'info, T: AccountSerialize + AccountDeserialize + Clone> Key for ProgramAccount<'info, T> {
-    fn key(&self) -> Pubkey {
-        *self.inner.info.key
-    }
-}

+ 1 - 19
lang/src/accounts/signer.rs

@@ -2,7 +2,6 @@
 use crate::error::ErrorCode;
 use crate::error::ErrorCode;
 use crate::*;
 use crate::*;
 use solana_program::account_info::AccountInfo;
 use solana_program::account_info::AccountInfo;
-use solana_program::entrypoint::ProgramResult;
 use solana_program::instruction::AccountMeta;
 use solana_program::instruction::AccountMeta;
 use solana_program::program_error::ProgramError;
 use solana_program::program_error::ProgramError;
 use solana_program::pubkey::Pubkey;
 use solana_program::pubkey::Pubkey;
@@ -71,12 +70,7 @@ impl<'info> Accounts<'info> for Signer<'info> {
     }
     }
 }
 }
 
 
-impl<'info> AccountsExit<'info> for Signer<'info> {
-    fn exit(&self, _program_id: &Pubkey) -> ProgramResult {
-        // No-op.
-        Ok(())
-    }
-}
+impl<'info> AccountsExit<'info> for Signer<'info> {}
 
 
 impl<'info> ToAccountMetas for Signer<'info> {
 impl<'info> ToAccountMetas for Signer<'info> {
     fn to_account_metas(&self, is_signer: Option<bool>) -> Vec<AccountMeta> {
     fn to_account_metas(&self, is_signer: Option<bool>) -> Vec<AccountMeta> {
@@ -95,12 +89,6 @@ impl<'info> ToAccountInfos<'info> for Signer<'info> {
     }
     }
 }
 }
 
 
-impl<'info> ToAccountInfo<'info> for Signer<'info> {
-    fn to_account_info(&self) -> AccountInfo<'info> {
-        self.info.clone()
-    }
-}
-
 impl<'info> AsRef<AccountInfo<'info>> for Signer<'info> {
 impl<'info> AsRef<AccountInfo<'info>> for Signer<'info> {
     fn as_ref(&self) -> &AccountInfo<'info> {
     fn as_ref(&self) -> &AccountInfo<'info> {
         &self.info
         &self.info
@@ -114,9 +102,3 @@ impl<'info> Deref for Signer<'info> {
         &self.info
         &self.info
     }
     }
 }
 }
-
-impl<'info> Key for Signer<'info> {
-    fn key(&self) -> Pubkey {
-        *self.info.key
-    }
-}

+ 2 - 18
lang/src/accounts/state.rs

@@ -2,8 +2,8 @@
 use crate::accounts::cpi_account::CpiAccount;
 use crate::accounts::cpi_account::CpiAccount;
 use crate::error::ErrorCode;
 use crate::error::ErrorCode;
 use crate::{
 use crate::{
-    AccountDeserialize, AccountSerialize, Accounts, AccountsExit, Key, ToAccountInfo,
-    ToAccountInfos, ToAccountMetas,
+    AccountDeserialize, AccountSerialize, Accounts, AccountsExit, ToAccountInfo, ToAccountInfos,
+    ToAccountMetas,
 };
 };
 use solana_program::account_info::AccountInfo;
 use solana_program::account_info::AccountInfo;
 use solana_program::entrypoint::ProgramResult;
 use solana_program::entrypoint::ProgramResult;
@@ -108,15 +108,6 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountInfos<'in
     }
     }
 }
 }
 
 
-#[allow(deprecated)]
-impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountInfo<'info>
-    for ProgramState<'info, T>
-{
-    fn to_account_info(&self) -> AccountInfo<'info> {
-        self.inner.info.clone()
-    }
-}
-
 #[allow(deprecated)]
 #[allow(deprecated)]
 impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AsRef<AccountInfo<'info>>
 impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AsRef<AccountInfo<'info>>
     for ProgramState<'info, T>
     for ProgramState<'info, T>
@@ -172,10 +163,3 @@ pub fn address(program_id: &Pubkey) -> Pubkey {
     let owner = program_id;
     let owner = program_id;
     Pubkey::create_with_seed(&base, seed, owner).unwrap()
     Pubkey::create_with_seed(&base, seed, owner).unwrap()
 }
 }
-
-#[allow(deprecated)]
-impl<'info, T: AccountSerialize + AccountDeserialize + Clone> Key for ProgramState<'info, T> {
-    fn key(&self) -> Pubkey {
-        *self.inner.info.key
-    }
-}

+ 1 - 19
lang/src/accounts/system_account.rs

@@ -3,7 +3,6 @@
 use crate::error::ErrorCode;
 use crate::error::ErrorCode;
 use crate::*;
 use crate::*;
 use solana_program::account_info::AccountInfo;
 use solana_program::account_info::AccountInfo;
-use solana_program::entrypoint::ProgramResult;
 use solana_program::instruction::AccountMeta;
 use solana_program::instruction::AccountMeta;
 use solana_program::program_error::ProgramError;
 use solana_program::program_error::ProgramError;
 use solana_program::pubkey::Pubkey;
 use solana_program::pubkey::Pubkey;
@@ -50,12 +49,7 @@ impl<'info> Accounts<'info> for SystemAccount<'info> {
     }
     }
 }
 }
 
 
-impl<'info> AccountsExit<'info> for SystemAccount<'info> {
-    fn exit(&self, _program_id: &Pubkey) -> ProgramResult {
-        // No-op.
-        Ok(())
-    }
-}
+impl<'info> AccountsExit<'info> for SystemAccount<'info> {}
 
 
 impl<'info> ToAccountMetas for SystemAccount<'info> {
 impl<'info> ToAccountMetas for SystemAccount<'info> {
     fn to_account_metas(&self, is_signer: Option<bool>) -> Vec<AccountMeta> {
     fn to_account_metas(&self, is_signer: Option<bool>) -> Vec<AccountMeta> {
@@ -74,12 +68,6 @@ impl<'info> ToAccountInfos<'info> for SystemAccount<'info> {
     }
     }
 }
 }
 
 
-impl<'info> ToAccountInfo<'info> for SystemAccount<'info> {
-    fn to_account_info(&self) -> AccountInfo<'info> {
-        self.info.clone()
-    }
-}
-
 impl<'info> AsRef<AccountInfo<'info>> for SystemAccount<'info> {
 impl<'info> AsRef<AccountInfo<'info>> for SystemAccount<'info> {
     fn as_ref(&self) -> &AccountInfo<'info> {
     fn as_ref(&self) -> &AccountInfo<'info> {
         &self.info
         &self.info
@@ -93,9 +81,3 @@ impl<'info> Deref for SystemAccount<'info> {
         &self.info
         &self.info
     }
     }
 }
 }
-
-impl<'info> Key for SystemAccount<'info> {
-    fn key(&self) -> Pubkey {
-        *self.info.key
-    }
-}

+ 2 - 20
lang/src/accounts/sysvar.rs

@@ -1,9 +1,8 @@
 //! Type validating that the account is a sysvar and deserializing it
 //! Type validating that the account is a sysvar and deserializing it
 
 
 use crate::error::ErrorCode;
 use crate::error::ErrorCode;
-use crate::{Accounts, AccountsExit, Key, ToAccountInfo, ToAccountInfos, ToAccountMetas};
+use crate::{Accounts, AccountsExit, ToAccountInfos, ToAccountMetas};
 use solana_program::account_info::AccountInfo;
 use solana_program::account_info::AccountInfo;
-use solana_program::entrypoint::ProgramResult;
 use solana_program::instruction::AccountMeta;
 use solana_program::instruction::AccountMeta;
 use solana_program::program_error::ProgramError;
 use solana_program::program_error::ProgramError;
 use solana_program::pubkey::Pubkey;
 use solana_program::pubkey::Pubkey;
@@ -112,21 +111,4 @@ impl<'a, T: solana_program::sysvar::Sysvar> DerefMut for Sysvar<'a, T> {
     }
     }
 }
 }
 
 
-impl<'info, T: solana_program::sysvar::Sysvar> ToAccountInfo<'info> for Sysvar<'info, T> {
-    fn to_account_info(&self) -> AccountInfo<'info> {
-        self.info.clone()
-    }
-}
-
-impl<'info, T: solana_program::sysvar::Sysvar> AccountsExit<'info> for Sysvar<'info, T> {
-    fn exit(&self, _program_id: &Pubkey) -> ProgramResult {
-        // no-op
-        Ok(())
-    }
-}
-
-impl<'info, T: solana_program::sysvar::Sysvar> Key for Sysvar<'info, T> {
-    fn key(&self) -> Pubkey {
-        *self.info.key
-    }
-}
+impl<'info, T: solana_program::sysvar::Sysvar> AccountsExit<'info> for Sysvar<'info, T> {}

+ 5 - 17
lang/src/accounts/unchecked_account.rs

@@ -2,9 +2,8 @@
 //! that no checks are performed
 //! that no checks are performed
 
 
 use crate::error::ErrorCode;
 use crate::error::ErrorCode;
-use crate::{Accounts, AccountsExit, Key, ToAccountInfo, ToAccountInfos, ToAccountMetas};
+use crate::{Accounts, AccountsExit, ToAccountInfos, ToAccountMetas};
 use solana_program::account_info::AccountInfo;
 use solana_program::account_info::AccountInfo;
-use solana_program::entrypoint::ProgramResult;
 use solana_program::instruction::AccountMeta;
 use solana_program::instruction::AccountMeta;
 use solana_program::program_error::ProgramError;
 use solana_program::program_error::ProgramError;
 use solana_program::pubkey::Pubkey;
 use solana_program::pubkey::Pubkey;
@@ -53,22 +52,11 @@ impl<'info> ToAccountInfos<'info> for UncheckedAccount<'info> {
     }
     }
 }
 }
 
 
-impl<'info> ToAccountInfo<'info> for UncheckedAccount<'info> {
-    fn to_account_info(&self) -> AccountInfo<'info> {
-        self.0.clone()
-    }
-}
-
-impl<'info> AccountsExit<'info> for UncheckedAccount<'info> {
-    fn exit(&self, _program_id: &Pubkey) -> ProgramResult {
-        // no-op
-        Ok(())
-    }
-}
+impl<'info> AccountsExit<'info> for UncheckedAccount<'info> {}
 
 
-impl<'info> Key for UncheckedAccount<'info> {
-    fn key(&self) -> Pubkey {
-        *self.key
+impl<'info> AsRef<AccountInfo<'info>> for UncheckedAccount<'info> {
+    fn as_ref(&self) -> &AccountInfo<'info> {
+        &self.0
     }
     }
 }
 }
 
 

+ 18 - 3
lang/src/lib.rs

@@ -87,7 +87,10 @@ pub trait Accounts<'info>: ToAccountMetas + ToAccountInfos<'info> + Sized {
 /// should be done here.
 /// should be done here.
 pub trait AccountsExit<'info>: ToAccountMetas + ToAccountInfos<'info> {
 pub trait AccountsExit<'info>: ToAccountMetas + ToAccountInfos<'info> {
     /// `program_id` is the currently executing program.
     /// `program_id` is the currently executing program.
-    fn exit(&self, program_id: &Pubkey) -> ProgramResult;
+    fn exit(&self, _program_id: &Pubkey) -> ProgramResult {
+        // no-op
+        Ok(())
+    }
 }
 }
 
 
 /// The close procedure to initiate garabage collection of an account, allowing
 /// The close procedure to initiate garabage collection of an account, allowing
@@ -120,6 +123,15 @@ pub trait ToAccountInfo<'info> {
     fn to_account_info(&self) -> AccountInfo<'info>;
     fn to_account_info(&self) -> AccountInfo<'info>;
 }
 }
 
 
+impl<'info, T> ToAccountInfo<'info> for T
+where
+    T: AsRef<AccountInfo<'info>>,
+{
+    fn to_account_info(&self) -> AccountInfo<'info> {
+        self.as_ref().clone()
+    }
+}
+
 /// A data structure that can be serialized and stored into account storage,
 /// A data structure that can be serialized and stored into account storage,
 /// i.e. an
 /// i.e. an
 /// [`AccountInfo`](../solana_program/account_info/struct.AccountInfo.html#structfield.data)'s
 /// [`AccountInfo`](../solana_program/account_info/struct.AccountInfo.html#structfield.data)'s
@@ -209,9 +221,12 @@ pub trait Key {
     fn key(&self) -> Pubkey;
     fn key(&self) -> Pubkey;
 }
 }
 
 
-impl Key for Pubkey {
+impl<'info, T> Key for T
+where
+    T: AsRef<AccountInfo<'info>>,
+{
     fn key(&self) -> Pubkey {
     fn key(&self) -> Pubkey {
-        *self
+        *self.as_ref().key
     }
     }
 }
 }