浏览代码

lang: implement AsRef<T> for Account<'a, T> (#1173)

Paul 3 年之前
父节点
当前提交
51366441d2
共有 2 个文件被更改,包括 9 次插入0 次删除
  1. 1 0
      CHANGELOG.md
  2. 8 0
      lang/src/accounts/account.rs

+ 1 - 0
CHANGELOG.md

@@ -25,6 +25,7 @@ incremented for features.
 * lang: Add `set_inner` method to `Account<'a, T>` to enable easy updates ([#1177](https://github.com/project-serum/anchor/pull/1177)).
 * lang: Add `set_inner` method to `Account<'a, T>` to enable easy updates ([#1177](https://github.com/project-serum/anchor/pull/1177)).
 * lang: Handle arrays with const as length ([#968](https://github.com/project-serum/anchor/pull/968)).
 * lang: Handle arrays with const as length ([#968](https://github.com/project-serum/anchor/pull/968)).
 * ts: Add optional commitment argument to `fetch` and `fetchMultiple` ([#1171](https://github.com/project-serum/anchor/pull/1171)).
 * ts: Add optional commitment argument to `fetch` and `fetchMultiple` ([#1171](https://github.com/project-serum/anchor/pull/1171)).
+* lang: Implement `AsRef<T>` for `Account<'a, T>`([#1173](https://github.com/project-serum/anchor/pull/1173))
 
 
 ### Breaking
 ### Breaking
 
 

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

@@ -160,6 +160,14 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Owner + Clone> AsRef<Acco
     }
     }
 }
 }
 
 
+impl<'info, T: AccountSerialize + AccountDeserialize + Owner + Clone> AsRef<T>
+    for Account<'info, T>
+{
+    fn as_ref(&self) -> &T {
+        &self.account
+    }
+}
+
 impl<'a, T: AccountSerialize + AccountDeserialize + Owner + Clone> Deref for Account<'a, T> {
 impl<'a, T: AccountSerialize + AccountDeserialize + Owner + Clone> Deref for Account<'a, T> {
     type Target = T;
     type Target = T;