Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ use alloc::{string::String, vec::Vec};
#[cfg(feature = "alloc")]
use alloc::format;

#[cfg(feature = "std")]
use std::io;
#[cfg(all(not(feature = "std"), feature = "core2"))]
use core2::io;

use core::{fmt, str};
use Hash;

Expand Down Expand Up @@ -135,6 +140,23 @@ impl<'a> Iterator for HexIterator<'a> {
}
}

#[cfg(any(feature = "std", feature = "core2"))]
impl<'a> io::Read for HexIterator<'a> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let mut bytes_read = 0usize;
for dst in buf {
match self.next() {
Some(Ok(src)) => {
*dst = src;
bytes_read += 1;
},
_ => break,
}
}
Ok(bytes_read)
}
}

impl<'a> DoubleEndedIterator for HexIterator<'a> {
fn next_back(&mut self) -> Option<Result<u8, Error>> {
let lo = self.iter.next_back()?;
Expand Down