From 39a3d5b8a9fc573eedec6edf538c2911f120e778 Mon Sep 17 00:00:00 2001 From: behzad nouri Date: Mon, 16 Aug 2021 18:21:33 +0000 Subject: [PATCH] implements AsRef (instead of Borrow) for VoteAccounts (#19252) According to the docs: > if you want to borrow only a single field of a struct you can > implement AsRef, but not Borrow. https://doc.rust-lang.org/std/convert/trait.AsRef.html --- runtime/src/stakes.rs | 4 ++-- runtime/src/vote_account.rs | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/runtime/src/stakes.rs b/runtime/src/stakes.rs index a28f3a5b68..50e004cb59 100644 --- a/runtime/src/stakes.rs +++ b/runtime/src/stakes.rs @@ -14,7 +14,7 @@ use { }, solana_stake_program::stake_state, solana_vote_program::vote_state::VoteState, - std::{borrow::Borrow, collections::HashMap, sync::Arc}, + std::{collections::HashMap, sync::Arc}, }; #[derive(Default, Clone, PartialEq, Debug, Deserialize, Serialize, AbiExample)] @@ -212,7 +212,7 @@ impl Stakes { } pub fn vote_accounts(&self) -> &HashMap { - self.vote_accounts.borrow() + self.vote_accounts.as_ref() } pub fn stake_delegations(&self) -> &HashMap { diff --git a/runtime/src/vote_account.rs b/runtime/src/vote_account.rs index dc385f9748..91539bc9d4 100644 --- a/runtime/src/vote_account.rs +++ b/runtime/src/vote_account.rs @@ -7,7 +7,6 @@ use { }, solana_vote_program::vote_state::VoteState, std::{ - borrow::Borrow, cmp::Ordering, collections::{hash_map::Entry, HashMap}, iter::FromIterator, @@ -268,8 +267,8 @@ impl From for VoteAccounts { } } -impl Borrow for VoteAccounts { - fn borrow(&self) -> &VoteAccountsHashMap { +impl AsRef for VoteAccounts { + fn as_ref(&self) -> &VoteAccountsHashMap { &self.vote_accounts } }