Skip to content

Commit

Permalink
clean up lifetime constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Mar 3, 2025
1 parent 6eff0c1 commit b3be0f4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
16 changes: 8 additions & 8 deletions vote/src/vote_state_view/field_frames.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use {
std::io::BufRead,
};

pub(super) trait ListFrame<'frame> {
type Item: 'frame;
pub(super) trait ListFrame {
type Item;

fn len(&self) -> usize;
fn item_size(&self) -> usize {
Expand All @@ -28,7 +28,7 @@ pub(super) enum VotesFrame {
Landed(LandedVotesListFrame),
}

impl ListFrame<'_> for VotesFrame {
impl ListFrame for VotesFrame {
type Item = LockoutItem;

fn len(&self) -> usize {
Expand Down Expand Up @@ -87,7 +87,7 @@ impl LockoutListFrame {
}
}

impl ListFrame<'_> for LockoutListFrame {
impl ListFrame for LockoutListFrame {
type Item = LockoutItem;

fn len(&self) -> usize {
Expand Down Expand Up @@ -119,7 +119,7 @@ pub(super) struct LandedVoteItem {
confirmation_count: [u8; 4],
}

impl ListFrame<'_> for LandedVotesListFrame {
impl ListFrame for LandedVotesListFrame {
type Item = LockoutItem;

fn len(&self) -> usize {
Expand Down Expand Up @@ -158,7 +158,7 @@ pub(super) struct AuthorizedVoterItem {
voter: Pubkey,
}

impl ListFrame<'_> for AuthorizedVotersListFrame {
impl ListFrame for AuthorizedVotersListFrame {
type Item = AuthorizedVoterItem;

fn len(&self) -> usize {
Expand Down Expand Up @@ -203,7 +203,7 @@ impl EpochCreditsListFrame {
}
}

impl ListFrame<'_> for EpochCreditsListFrame {
impl ListFrame for EpochCreditsListFrame {
type Item = EpochCreditsItem;

fn len(&self) -> usize {
Expand Down Expand Up @@ -288,7 +288,7 @@ impl RootSlotFrame {

pub(super) struct PriorVotersFrame;

impl ListFrame<'_> for PriorVotersFrame {
impl ListFrame for PriorVotersFrame {
type Item = PriorVotersItem;

fn len(&self) -> usize {
Expand Down
12 changes: 9 additions & 3 deletions vote/src/vote_state_view/list_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub(super) struct ListView<'a, F> {
item_buffer: &'a [u8],
}

impl<'a, F: ListFrame<'a>> ListView<'a, F> {
impl<'a, F: ListFrame> ListView<'a, F> {
pub(super) fn new(frame: F, buffer: &'a [u8]) -> Self {
let len_offset = core::mem::size_of::<u64>();
let item_buffer = &buffer[len_offset..];
Expand Down Expand Up @@ -53,7 +53,10 @@ pub(super) struct ListViewIter<'a, F> {
view: ListView<'a, F>,
}

impl<'a, F: ListFrame<'a>> Iterator for ListViewIter<'a, F> {
impl<'a, F: ListFrame> Iterator for ListViewIter<'a, F>
where
F::Item: 'a,
{
type Item = &'a F::Item;
fn next(&mut self) -> Option<Self::Item> {
if self.index < self.view.len() {
Expand All @@ -66,7 +69,10 @@ impl<'a, F: ListFrame<'a>> Iterator for ListViewIter<'a, F> {
}
}

impl<'a, F: ListFrame<'a>> DoubleEndedIterator for ListViewIter<'a, F> {
impl<'a, F: ListFrame> DoubleEndedIterator for ListViewIter<'a, F>
where
F::Item: 'a,
{
fn next_back(&mut self) -> Option<Self::Item> {
if self.rev_index < self.view.len() {
let item = self.view.item(self.view.len() - self.rev_index - 1);
Expand Down

0 comments on commit b3be0f4

Please sign in to comment.