Skip to content

Commit

Permalink
Merge pull request #144 from ikrivosheev/feature/iterator_for_box
Browse files Browse the repository at this point in the history
feat: Implemented MemoryBlockIterator for Box
  • Loading branch information
Hugal31 authored Feb 6, 2024
2 parents 66d0795 + 8d78f8c commit b4b4343
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/internals/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,54 @@ pub trait MemoryBlockIterator {
fn next(&mut self) -> Option<MemoryBlock>;
}

impl<T> MemoryBlockIterator for Box<T>
where
T: MemoryBlockIterator,
{
fn first(&mut self) -> Option<MemoryBlock> {
(**self).first()
}

fn next(&mut self) -> Option<MemoryBlock> {
(**self).next()
}
}

impl<T> MemoryBlockIterator for &mut T
where
T: MemoryBlockIterator,
{
fn first(&mut self) -> Option<MemoryBlock> {
(**self).first()
}

fn next(&mut self) -> Option<MemoryBlock> {
(**self).next()
}
}

pub trait MemoryBlockIteratorSized: MemoryBlockIterator {
fn file_size(&mut self) -> u64;
}

impl<T> MemoryBlockIteratorSized for Box<T>
where
T: MemoryBlockIteratorSized,
{
fn file_size(&mut self) -> u64 {
(**self).file_size()
}
}

impl<T> MemoryBlockIteratorSized for &mut T
where
T: MemoryBlockIteratorSized,
{
fn file_size(&mut self) -> u64 {
(**self).file_size()
}
}

#[derive(Debug)]
pub struct WrapperMemoryBlockIterator<T> {
iter: T,
Expand Down

0 comments on commit b4b4343

Please sign in to comment.