Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

runtime: transpose VoteAccount::vote_state() return to improve ergonomics #31256

Merged
merged 1 commit into from
Apr 18, 2023

Conversation

t-nelson
Copy link
Contributor

Problem

VoteAccount::vote_state() returns an &Result<..., forcing every call site to .as_ref() et. all on use.

Summary of Changes

internally transpose the referencing. clean up call sites

this was very satisfying. i wish i'd caught it on review 😅

@@ -65,12 +65,13 @@ impl VoteAccount {
self.0.account.owner()
}

pub fn vote_state(&self) -> &Result<VoteState, Error> {
pub fn vote_state(&self) -> Result<&VoteState, &Error> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the tradeoff is that this return type is ugly/weird.
Is the .as_ref() at call-sites really a big deal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would argue that &Result<T, E> is uglier than Result<&T, &E>. we prefer Option<&T> to &Option<T> in most cases elsewhere to avoid the eye-twitch-inducing &None. ofc, this would all be better if it were Result<&T, E>, but i don't think we can get to that without jumping through hoops

core/src/replay_stage.rs Show resolved Hide resolved
runtime/src/bank.rs Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Apr 18, 2023

Codecov Report

Merging #31256 (4dc4cbc) into master (f5fe260) will increase coverage by 0.0%.
The diff coverage is 100.0%.

@@           Coverage Diff           @@
##           master   #31256   +/-   ##
=======================================
  Coverage    81.5%    81.5%           
=======================================
  Files         729      729           
  Lines      206621   206622    +1     
=======================================
+ Hits       168484   168525   +41     
+ Misses      38137    38097   -40     

@t-nelson t-nelson merged commit f34a6bc into solana-labs:master Apr 18, 2023
@t-nelson t-nelson deleted the vavst branch April 18, 2023 20:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants