Struct spectrusty_formats::tap::pulse::ReadEncPulseIter
source · pub struct ReadEncPulseIter<R> { /* private fields */ }
Expand description
Encodes data read from an underlying reader as TAPE T-state pulse intervals via an Iterator interface.
The timing of the pulses matches those expected by ZX Spectrum’s ROM loading routines.
After invoking ReadEncPulseIter::reset or ReadEncPulseIter::new the first byte is read and checked to determine the duration of the LEAD PULSE signal. If it’s less than 128 the number of generated lead pulses is LEAD_PULSES_HEAD. Otherwise, it’s LEAD_PULSES_DATA.
After the lead pulses, two synchronization pulses are being emitted following by data pulses for each byte read including the initial flag byte.
This iterator may be used to feed pulses to the EAR IN
buffer of the ZX Spectrum emulator
(e.g. via EarIn::feed_ear_in)
or to produce sound with a help of Bandwidth-Limited Pulse Buffer.
Best used with tap utilities.
Implementations§
source§impl<R> ReadEncPulseIter<R>
impl<R> ReadEncPulseIter<R>
sourcepub fn state(&self) -> &PulseIterState
pub fn state(&self) -> &PulseIterState
Returns a reference to the current state.
sourcepub fn err(&self) -> Option<&Error>
pub fn err(&self) -> Option<&Error>
Returns an error from the underlying reader if there was one.
Examples found in repository?
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
fn next(&mut self) -> Option<Self::Item> {
match self.ep_iter.next() {
pulse @ Some(_) => pulse,
None if self.auto_next => {
if self.ep_iter.err().is_some() ||
self.ep_iter.get_mut().next_chunk().is_err() {
return None;
}
self.ep_iter.reset();
if self.ep_iter.is_done() {
None
}
else {
Some(PAUSE_PULSE_LENGTH)
}
}
None => None
}
}
sourcepub fn is_done(&self) -> bool
pub fn is_done(&self) -> bool
Returns true
if there are no more pulses to emit or there
was an error while bytes were read.
Examples found in repository?
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
pub fn is_done(&self) -> bool {
self.ep_iter.is_done()
}
}
impl<R: Read + Seek> TapChunkRead for TapChunkPulseIter<R> {
fn chunk_no(&self) -> u32 {
self.ep_iter.get_ref().chunk_no()
}
fn chunk_limit(&self) -> u16 {
self.ep_iter.get_ref().chunk_limit()
}
/// Invokes underlying [TapChunkReader::rewind] and [resets][ReadEncPulseIter::reset] the internal
/// pulse iterator. Returns the result from [TapChunkReader::rewind].
fn rewind(&mut self) {
self.ep_iter.get_mut().rewind();
self.ep_iter.reset();
}
/// Invokes underlying [TapChunkReader::next_chunk] and [resets][ReadEncPulseIter::reset] the internal
/// pulse iterator. Returns the result from [TapChunkReader::next_chunk].
fn next_chunk(&mut self) -> Result<Option<u16>> {
let res = self.ep_iter.get_mut().next_chunk()?;
self.ep_iter.reset();
Ok(res)
}
/// Invokes underlying [TapChunkReader::skip_chunks] and [resets][ReadEncPulseIter::reset] the internal
/// pulse iterator. Returns the result from [TapChunkReader::skip_chunks].
fn skip_chunks(&mut self, skip: u32) -> Result<Option<u16>> {
let res = self.ep_iter.get_mut().skip_chunks(skip)?;
self.ep_iter.reset();
Ok(res)
}
}
impl<R> AsRef<TapChunkReader<R>> for TapChunkPulseIter<R> {
fn as_ref(&self) -> &TapChunkReader<R> {
self.ep_iter.get_ref()
}
}
impl<R> AsMut<TapChunkReader<R>> for TapChunkPulseIter<R> {
fn as_mut(&mut self) -> &mut TapChunkReader<R> {
self.ep_iter.get_mut()
}
}
impl<R: Read + Seek> Iterator for TapChunkPulseIter<R> {
type Item = NonZeroU32;
fn next(&mut self) -> Option<Self::Item> {
match self.ep_iter.next() {
pulse @ Some(_) => pulse,
None if self.auto_next => {
if self.ep_iter.err().is_some() ||
self.ep_iter.get_mut().next_chunk().is_err() {
return None;
}
self.ep_iter.reset();
if self.ep_iter.is_done() {
None
}
else {
Some(PAUSE_PULSE_LENGTH)
}
}
None => None
}
}
sourcepub fn get_mut(&mut self) -> &mut R
pub fn get_mut(&mut self) -> &mut R
Returns a mutable reference to the inner reader.
Examples found in repository?
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
fn rewind(&mut self) {
self.ep_iter.get_mut().rewind();
self.ep_iter.reset();
}
/// Invokes underlying [TapChunkReader::next_chunk] and [resets][ReadEncPulseIter::reset] the internal
/// pulse iterator. Returns the result from [TapChunkReader::next_chunk].
fn next_chunk(&mut self) -> Result<Option<u16>> {
let res = self.ep_iter.get_mut().next_chunk()?;
self.ep_iter.reset();
Ok(res)
}
/// Invokes underlying [TapChunkReader::skip_chunks] and [resets][ReadEncPulseIter::reset] the internal
/// pulse iterator. Returns the result from [TapChunkReader::skip_chunks].
fn skip_chunks(&mut self, skip: u32) -> Result<Option<u16>> {
let res = self.ep_iter.get_mut().skip_chunks(skip)?;
self.ep_iter.reset();
Ok(res)
}
}
impl<R> AsRef<TapChunkReader<R>> for TapChunkPulseIter<R> {
fn as_ref(&self) -> &TapChunkReader<R> {
self.ep_iter.get_ref()
}
}
impl<R> AsMut<TapChunkReader<R>> for TapChunkPulseIter<R> {
fn as_mut(&mut self) -> &mut TapChunkReader<R> {
self.ep_iter.get_mut()
}
}
impl<R: Read + Seek> Iterator for TapChunkPulseIter<R> {
type Item = NonZeroU32;
fn next(&mut self) -> Option<Self::Item> {
match self.ep_iter.next() {
pulse @ Some(_) => pulse,
None if self.auto_next => {
if self.ep_iter.err().is_some() ||
self.ep_iter.get_mut().next_chunk().is_err() {
return None;
}
self.ep_iter.reset();
if self.ep_iter.is_done() {
None
}
else {
Some(PAUSE_PULSE_LENGTH)
}
}
None => None
}
}
sourcepub fn get_ref(&self) -> &R
pub fn get_ref(&self) -> &R
Returns a shared reference to the inner reader.
Examples found in repository?
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
fn chunk_no(&self) -> u32 {
self.ep_iter.get_ref().chunk_no()
}
fn chunk_limit(&self) -> u16 {
self.ep_iter.get_ref().chunk_limit()
}
/// Invokes underlying [TapChunkReader::rewind] and [resets][ReadEncPulseIter::reset] the internal
/// pulse iterator. Returns the result from [TapChunkReader::rewind].
fn rewind(&mut self) {
self.ep_iter.get_mut().rewind();
self.ep_iter.reset();
}
/// Invokes underlying [TapChunkReader::next_chunk] and [resets][ReadEncPulseIter::reset] the internal
/// pulse iterator. Returns the result from [TapChunkReader::next_chunk].
fn next_chunk(&mut self) -> Result<Option<u16>> {
let res = self.ep_iter.get_mut().next_chunk()?;
self.ep_iter.reset();
Ok(res)
}
/// Invokes underlying [TapChunkReader::skip_chunks] and [resets][ReadEncPulseIter::reset] the internal
/// pulse iterator. Returns the result from [TapChunkReader::skip_chunks].
fn skip_chunks(&mut self, skip: u32) -> Result<Option<u16>> {
let res = self.ep_iter.get_mut().skip_chunks(skip)?;
self.ep_iter.reset();
Ok(res)
}
}
impl<R> AsRef<TapChunkReader<R>> for TapChunkPulseIter<R> {
fn as_ref(&self) -> &TapChunkReader<R> {
self.ep_iter.get_ref()
}
sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Returns the underlying reader.
sourcepub fn with_state_and_flag(self, state: PulseIterState, flag: u8) -> Self
pub fn with_state_and_flag(self, state: PulseIterState, flag: u8) -> Self
Allows to manually assign a state
and a flag
.
Can be used to deserialize ReadEncPulseIter.
source§impl<R: Read> ReadEncPulseIter<R>
impl<R: Read> ReadEncPulseIter<R>
sourcepub fn new(rd: R) -> Self
pub fn new(rd: R) -> Self
Creates a new ReadEncPulseIter
from a given Reader.
Examples found in repository?
More examples
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818
pub fn read_tap_pulse_iter<T, R>(rd: T) -> TapChunkPulseIter<R>
where R: Read + Seek, T: Into<TapChunkReader<R>>
{
let ep_iter = ReadEncPulseIter::new(rd.into());
TapChunkPulseIter::from(ep_iter)
}
/// Creates an instance of [TapChunkWriter] from the given writer on success.
pub fn write_tap<W>(wr: W) -> Result<TapChunkWriter<W>>
where W: Write + Seek
{
TapChunkWriter::try_new(wr)
}
/// The *TAP* block type of the next chunk following a [Header].
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(u8)]
pub enum BlockType {
Program = 0,
NumberArray = 1,
CharArray = 2,
Code = 3
}
/// Represents the *TAP* header block.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Header {
/// Length of the data block excluding a block flag and checksum byte.
pub length: u16,
/// The type of the file this header represents.
pub block_type: BlockType,
/// A name of the file.
pub name: [u8;10],
/// Additional header data.
pub par1: [u8;2],
/// Additional header data.
pub par2: [u8;2]
}
/// The *TAP* chunk meta-data.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum TapChunkInfo {
/// Represents a proper header block.
Head(Header),
/// Represents a data block.
Data {
/// The length of data excluding a block flag and checksum byte.
length: u16,
/// Checksum of the data, should be 0. Otherwise this block won't load properly.
checksum: u8
},
/// Represents an unkown block.
Unknown {
/// The size of the whole block including the block flag.
size: u16,
/// The first byte of the block (a block flag).
flag: u8
},
/// Represents an empty block.
Empty
}
/// The *TAP* chunk.
///
/// Provides helper methods to interpret the underlying bytes as one of the *TAP* blocks.
/// This should usually be a [Header] or a data block.
///
/// Anything that implements `AsRef<[u8]>` can be used as `T` (e.g. `&[u8]` or `Vec<u8>`).
///
/// Instances of [TapChunk] can be created using [From]/[Into] interface or via [TapChunkIter].
#[derive(Clone, Copy, Debug)]
pub struct TapChunk<T> {
data: T
}
/// Implements an iterator of [TapChunk] objects over the array of bytes.
#[derive(Clone, Debug)]
pub struct TapChunkIter<'a> {
position: usize,
data: &'a[u8]
}
#[inline(always)]
pub(super) fn array_name(c: u8) -> char {
(c & 0b0001_1111 | 0b0100_0000).into()
}
#[inline(always)]
pub(super) fn char_array_var(n: char) -> u8 {
if !n.is_ascii_alphabetic() {
panic!("Only ascii alphabetic characters are allowed!");
}
let c = n as u8;
c & 0b0001_1111 | 0b1100_0000
}
#[inline(always)]
pub(super) fn number_array_var(n: char) -> u8 {
if !n.is_ascii_alphabetic() {
panic!("Only ascii alphabetic characters are allowed!");
}
let c = n as u8;
c & 0b0001_1111 | 0b1000_0000
}
impl fmt::Display for BlockType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}",
match self {
BlockType::Program => "Program",
BlockType::NumberArray => "Number array",
BlockType::CharArray => "Character array",
BlockType::Code => "Bytes",
})
}
}
impl fmt::Display for TapChunkInfo {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TapChunkInfo::Head(header) => {
write!(f, "{}: \"{}\"", header.block_type, header.name_str().trim_end())?;
match header.block_type {
BlockType::Program => {
if header.start() < 10000 {
write!(f, " LINE {}", header.start())?;
}
if header.vars() != header.length {
write!(f, " PROG {} VARS {}",
header.vars(), header.length - header.vars())?;
}
Ok(())
}
BlockType::NumberArray => {
write!(f, " DATA {}()", header.array_name())
}
BlockType::CharArray => {
write!(f, " DATA {}$()", header.array_name())
}
BlockType::Code => {
write!(f, " CODE {},{}", header.start(), header.length)
}
}
}
TapChunkInfo::Data {length, ..} => {
write!(f, "(data {})", length)
}
TapChunkInfo::Unknown {size, ..} => {
write!(f, "(unkown {})", size)
}
TapChunkInfo::Empty => {
write!(f, "(empty)")
}
}
}
}
impl<T> fmt::Display for TapChunk<T> where T: AsRef<[u8]> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.info() {
Ok(info) => info.fmt(f),
Err(e) => write!(f, "{}", e)
}
}
}
impl Default for BlockType {
fn default() -> Self {
BlockType::Code
}
}
impl From<BlockType> for u8 {
#[inline]
fn from(block_type: BlockType) -> u8 {
block_type as u8
}
}
impl TryFrom<u8> for BlockType {
type Error = Error;
#[inline]
fn try_from(block_type: u8) -> Result<Self> {
match block_type {
0 => Ok(BlockType::Program),
1 => Ok(BlockType::NumberArray),
2 => Ok(BlockType::CharArray),
3 => Ok(BlockType::Code),
_ => Err(Error::new(ErrorKind::InvalidData, "Unknown TAP type."))
}
}
}
impl Default for Header {
fn default() -> Self {
let length = 0;
let block_type = BlockType::Code;
let name = [b' ';10];
let par1 = 0u16.to_le_bytes();
let par2 = 0x8000u16.to_le_bytes();
Header { length, block_type, name, par1, par2 }
}
}
impl Header {
/// Creates a `Code` header.
pub fn new_code(length: u16) -> Self {
let block_type = BlockType::Code;
let name = [b' ';10];
let par1 = 0u16.to_le_bytes();
let par2 = 0x8000u16.to_le_bytes();
Header { length, block_type, name, par1, par2 }
}
/// Creates a `Program` header.
pub fn new_program(length: u16) -> Self {
let block_type = BlockType::Program;
let name = [b' ';10];
let par1 = 0x8000u16.to_le_bytes();
let par2 = length.to_le_bytes();
Header { length, block_type, name, par1, par2 }
}
/// Creates a `NumberArray` header.
pub fn new_number_array(length: u16) -> Self {
let block_type = BlockType::NumberArray;
let name = [b' ';10];
let par1 = [0, number_array_var('A')];
let par2 = 0x8000u16.to_le_bytes();
Header { length, block_type, name, par1, par2 }
}
/// Creates a `CharArray` header.
pub fn new_char_array(length: u16) -> Self {
let block_type = BlockType::CharArray;
let name = [b' ';10];
let par1 = [0, char_array_var('A')];
let par2 = 0x8000u16.to_le_bytes();
Header { length, block_type, name, par1, par2 }
}
/// Changes `name`, builder style.
pub fn with_name<S: AsRef<[u8]>>(mut self, name: S) -> Self {
let name = name.as_ref();
let bname = &name[0..name.len().max(10)];
self.name[0..bname.len()].copy_from_slice(bname);
for p in self.name[bname.len()..].iter_mut() {
*p = b' ';
}
self
}
/// Changes `start`, builder style.
///
/// # Panics
/// Panics if self is not a `Code` nor a `Program` header.
pub fn with_start(mut self, start: u16) -> Self {
if let BlockType::Code|BlockType::Program = self.block_type {
self.par1 = start.to_le_bytes();
self
}
else {
panic!("Can't set start for an array header");
}
}
/// Changes `vars`, builder style.
///
/// # Panics
/// Panics if self is not a `Program` header or if given `vars` exceeds `length`.
pub fn with_vars(mut self, vars: u16) -> Self {
if let BlockType::Program = self.block_type {
if vars <= self.length {
self.par2 = vars.to_le_bytes();
self
}
else {
panic!("Can't set vars larger than length");
}
}
else {
panic!("Can't set vars: not a program header");
}
}
/// Changes array name, builder style.
///
/// # Panics
/// Panics if self is not an array header or if given character is not ASCII alphabetic.
pub fn with_array_name(mut self, n: char) -> Self {
self.par1[1] = match self.block_type {
BlockType::CharArray => char_array_var(n),
BlockType::NumberArray => number_array_var(n),
_ => panic!("Can't set array name: not an array header")
};
self
}
/// Returns a header name as a string.
#[inline]
pub fn name_str(&self) -> Cow<'_, str> {
String::from_utf8_lossy(&self.name)
}
/// Returns a starting address.
/// Depending of the type of this header it may be either a starting address of [BlockType::Code]
/// or starting line of [BlockType::Program].
#[inline]
pub fn start(&self) -> u16 {
u16::from_le_bytes(self.par1)
}
/// Returns an offset to `VARS`. Only valid for headers with [BlockType::Program].
#[inline]
pub fn vars(&self) -> u16 {
u16::from_le_bytes(self.par2)
}
/// Returns an array variable name.
///
/// Only valid for headers with [BlockType::CharArray] or [BlockType::NumberArray].
#[inline]
pub fn array_name(&self) -> char {
array_name(self.par1[1])
}
/// Returns a tap chunk created from self.
pub fn to_tap_chunk(&self) -> TapChunk<[u8;HEADER_SIZE]> {
let mut buffer = <[u8;HEADER_SIZE]>::default();
buffer[0] = HEAD_BLOCK_FLAG;
buffer[1] = self.block_type.into();
buffer[2..12].copy_from_slice(&self.name);
buffer[12..14].copy_from_slice(&self.length.to_le_bytes());
buffer[14..16].copy_from_slice(&self.par1);
buffer[16..18].copy_from_slice(&self.par2);
buffer[18] = checksum(buffer[0..18].iter());
TapChunk::from(buffer)
}
}
impl TryFrom<&'_[u8]> for Header {
type Error = Error;
fn try_from(header: &[u8]) -> Result<Self> {
if header.len() != HEADER_SIZE - 2 {
return Err(Error::new(ErrorKind::InvalidData, "Not a proper TAP header: invalid length"));
}
let block_type = BlockType::try_from(header[0])?;
let mut name: [u8; 10] = Default::default();
name.copy_from_slice(&header[1..11]);
let mut length: [u8; 2] = Default::default();
length.copy_from_slice(&header[11..13]);
let length = u16::from_le_bytes(length);
let mut par1: [u8; 2] = Default::default();
par1.copy_from_slice(&header[13..15]);
let mut par2: [u8; 2] = Default::default();
par2.copy_from_slice(&header[15..17]);
Ok(Header { length, block_type, name, par1, par2 })
}
}
impl TapChunkInfo {
/// Returns size in bytes of this chunk.
pub fn tap_chunk_size(&self) -> usize {
match self {
TapChunkInfo::Head(_) => HEADER_SIZE,
&TapChunkInfo::Data {length, ..} => length as usize + 2,
&TapChunkInfo::Unknown {size, ..} => size as usize,
TapChunkInfo::Empty => 0
}
}
}
impl TryFrom<&'_[u8]> for TapChunkInfo {
type Error = Error;
#[inline]
fn try_from(bytes: &[u8]) -> Result<Self> {
let size = match bytes.len() {
0 => {
return Ok(TapChunkInfo::Empty);
}
1 => {
return Ok(TapChunkInfo::Unknown { size: 1, flag: bytes[0] })
}
size if size > u16::max_value().into() => {
return Err(Error::new(ErrorKind::InvalidData, "Not a proper TAP chunk: too large"));
}
size => size
};
match bytes.first() {
Some(&HEAD_BLOCK_FLAG) if size == HEADER_SIZE && checksum(bytes) == 0 => {
Header::try_from(&bytes[1..HEADER_SIZE-1])
.map(TapChunkInfo::Head)
.or(Ok(TapChunkInfo::Unknown { size: size as u16, flag: HEAD_BLOCK_FLAG }))
}
Some(&DATA_BLOCK_FLAG) => {
let checksum = checksum(bytes);
Ok(TapChunkInfo::Data{ length: size as u16 - 2, checksum })
}
Some(&flag) => {
Ok(TapChunkInfo::Unknown { size: size as u16, flag })
}
_ => unreachable!()
}
}
}
impl<T> From<T> for TapChunk<T> where T: AsRef<[u8]> {
fn from(data: T) -> Self {
TapChunk { data }
}
}
impl<T> AsRef<[u8]> for TapChunk<T> where T: AsRef<[u8]> {
#[inline(always)]
fn as_ref(&self) -> &[u8] {
self.data.as_ref()
}
}
impl<T> AsMut<[u8]> for TapChunk<T> where T: AsMut<[u8]> {
#[inline(always)]
fn as_mut(&mut self) -> &mut [u8] {
self.data.as_mut()
}
}
impl<T> TapChunk<T> {
/// Returns the underlying bytes container.
pub fn into_inner(self) -> T {
self.data
}
}
impl<T> TapChunk<T> where T: AsRef<[u8]> {
/// Attempts to create an instance of [TapChunkInfo] from underlying data.
pub fn info(&self) -> Result<TapChunkInfo> {
TapChunkInfo::try_from(self.data.as_ref())
}
/// Calculates bit-xor checksum of underlying data.
pub fn checksum(&self) -> u8 {
checksum(self.data.as_ref())
}
/// Checks if this *TAP* chunk is a [Header] block.
pub fn is_head(&self) -> bool {
matches!(self.data.as_ref().get(0..2),
Some(&[HEAD_BLOCK_FLAG, t]) if t & 3 == t)
}
/// Checks if this *TAP* chunk is a data block.
pub fn is_data(&self) -> bool {
matches!(self.data.as_ref().first(), Some(&DATA_BLOCK_FLAG))
}
/// Checks if this *TAP* chunk is a valid data or [Header] block.
pub fn is_valid(&self) -> bool {
self.validate().is_ok()
}
/// Validates if this *TAP* chunk is a valid data or [Header] block returning `self` on success.
pub fn validated(self) -> Result<Self> {
self.validate().map(|_| self)
}
/// Validates if this *TAP* chunk is a valid data or [Header] block.
pub fn validate(&self) -> Result<()> {
let data = self.data.as_ref();
match data.get(0..2) {
Some(&[HEAD_BLOCK_FLAG, t]) if t & 3 == t => {
if data.len() != HEADER_SIZE {
return Err(Error::new(ErrorKind::InvalidData, "Not a proper TAP header: invalid length"));
}
}
Some(&[DATA_BLOCK_FLAG, _]) => {}
_ => return Err(Error::new(ErrorKind::InvalidData, "Not a proper TAP chunk: Invalid block head byte"))
}
if checksum(data) != 0 {
return Err(Error::new(ErrorKind::InvalidData, "Not a proper TAP chunk: Invalid checksum"))
}
Ok(())
}
/// Returns a name if the block is a [Header]
pub fn name(&self) -> Option<Cow<'_,str>> {
if self.is_head() {
Some(String::from_utf8_lossy(&self.data.as_ref()[2..12]))
}
else {
None
}
}
/// Returns a reference to the underlying data block only if the underlying bytes represents the data block.
///
/// The provided reference does not include block flag and checksum bytes.
pub fn data(&self) -> Option<&[u8]> {
let data = self.data.as_ref();
if self.is_data() {
Some(&data[1..data.len()-1])
}
else {
None
}
}
/// Returns a length in bytes of the next chunk's data block only if the underlying bytes represents
/// the [Header] block.
///
/// The provided length does not include block flag and checksum bytes.
pub fn data_block_len(&self) -> Option<u16> {
if self.is_head() {
if let [lo, hi] = self.data.as_ref()[12..14] {
return Some(u16::from_le_bytes([lo, hi]))
}
}
None
}
/// Returns a starting address only if the underlying bytes represents the [Header] block.
///
/// Depending of the type of this header it may be either a starting address of [BlockType::Code]
/// or starting line of [BlockType::Program].
pub fn start(&self) -> Option<u16> {
if self.is_head() {
if let [lo, hi] = self.data.as_ref()[14..16] {
return Some(u16::from_le_bytes([lo, hi]))
}
}
None
}
/// Returns an offset to `VARS` only if the underlying bytes represents the [Header] block.
///
/// Only valid for headers with [BlockType::Program].
pub fn vars(&self) -> Option<u16> {
if self.is_head() {
if let [lo, hi] = self.data.as_ref()[16..18] {
return Some(u16::from_le_bytes([lo, hi]))
}
}
None
}
/// Returns an array variable name only if the underlying bytes represents the [Header] block.
///
/// Only valid for headers with [BlockType::CharArray] or [BlockType::NumberArray].
pub fn array_name(&self) -> Option<char> {
if self.is_head() {
return Some(array_name(self.data.as_ref()[15]))
}
None
}
/// Returns a next chunk's data type only if the underlying bytes represents the [Header] block.
pub fn block_type(&self) -> Option<BlockType> {
if self.is_head() {
return BlockType::try_from(self.data.as_ref()[1]).ok()
}
None
}
/// Returns a pulse interval iterator referencing this *TAP* chunk.
pub fn as_pulse_iter(&self) -> ReadEncPulseIter<Cursor<&[u8]>> {
ReadEncPulseIter::new(Cursor::new(self.as_ref()))
}
/// Converts this *TAP* chunk into a pulse interval iterator owning this chunk's data.
pub fn into_pulse_iter(self) -> ReadEncPulseIter<Cursor<T>> {
ReadEncPulseIter::new(Cursor::new(self.into_inner()))
}
sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Resets the state of the iterator.
The next byte read from the inner reader is interpreted as a flag byte to determine
the number of lead pulses. In this instance the state
becomes PulseIterState::Lead.
If there are no more bytes to be read the state
becomes PulseIterState::Done.
In case of an error while reading from the underlying reader the state
becomes PulseIterState::Error.
Examples found in repository?
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
fn rewind(&mut self) {
self.ep_iter.get_mut().rewind();
self.ep_iter.reset();
}
/// Invokes underlying [TapChunkReader::next_chunk] and [resets][ReadEncPulseIter::reset] the internal
/// pulse iterator. Returns the result from [TapChunkReader::next_chunk].
fn next_chunk(&mut self) -> Result<Option<u16>> {
let res = self.ep_iter.get_mut().next_chunk()?;
self.ep_iter.reset();
Ok(res)
}
/// Invokes underlying [TapChunkReader::skip_chunks] and [resets][ReadEncPulseIter::reset] the internal
/// pulse iterator. Returns the result from [TapChunkReader::skip_chunks].
fn skip_chunks(&mut self, skip: u32) -> Result<Option<u16>> {
let res = self.ep_iter.get_mut().skip_chunks(skip)?;
self.ep_iter.reset();
Ok(res)
}
}
impl<R> AsRef<TapChunkReader<R>> for TapChunkPulseIter<R> {
fn as_ref(&self) -> &TapChunkReader<R> {
self.ep_iter.get_ref()
}
}
impl<R> AsMut<TapChunkReader<R>> for TapChunkPulseIter<R> {
fn as_mut(&mut self) -> &mut TapChunkReader<R> {
self.ep_iter.get_mut()
}
}
impl<R: Read + Seek> Iterator for TapChunkPulseIter<R> {
type Item = NonZeroU32;
fn next(&mut self) -> Option<Self::Item> {
match self.ep_iter.next() {
pulse @ Some(_) => pulse,
None if self.auto_next => {
if self.ep_iter.err().is_some() ||
self.ep_iter.get_mut().next_chunk().is_err() {
return None;
}
self.ep_iter.reset();
if self.ep_iter.is_done() {
None
}
else {
Some(PAUSE_PULSE_LENGTH)
}
}
None => None
}
}
More examples
sourcepub fn data_from_next(&mut self)
pub fn data_from_next(&mut self)
Attempts to set the state of the iterator as PulseIterState::Data from the next byte.
The next byte read from the inner reader is interpreted as a data byte.
In this instance, the state
becomes PulseIterState::Data.
If there are no more bytes to be read the state
becomes PulseIterState::Done.
In case of an error while reading from the underlying reader the state
becomes PulseIterState::Error.
Trait Implementations§
source§impl<R: Debug> Debug for ReadEncPulseIter<R>
impl<R: Debug> Debug for ReadEncPulseIter<R>
source§impl<R: Read + Seek> From<ReadEncPulseIter<TapChunkReader<R>>> for TapChunkPulseIter<R>
impl<R: Read + Seek> From<ReadEncPulseIter<TapChunkReader<R>>> for TapChunkPulseIter<R>
source§fn from(ep_iter: ReadEncPulseIter<TapChunkReader<R>>) -> Self
fn from(ep_iter: ReadEncPulseIter<TapChunkReader<R>>) -> Self
source§impl<R: Read> Iterator for ReadEncPulseIter<R>
impl<R: Read> Iterator for ReadEncPulseIter<R>
§type Item = NonZeroU32
type Item = NonZeroU32
source§fn next(&mut self) -> Option<NonZeroU32>
fn next(&mut self) -> Option<NonZeroU32>
source§fn next_chunk<const N: usize>(
&mut self
) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>where
Self: Sized,
fn next_chunk<const N: usize>(
&mut self
) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>where
Self: Sized,
iter_next_chunk
)N
values. Read more1.0.0 · source§fn size_hint(&self) -> (usize, Option<usize>)
fn size_hint(&self) -> (usize, Option<usize>)
1.0.0 · source§fn count(self) -> usizewhere
Self: Sized,
fn count(self) -> usizewhere
Self: Sized,
1.0.0 · source§fn last(self) -> Option<Self::Item>where
Self: Sized,
fn last(self) -> Option<Self::Item>where
Self: Sized,
source§fn advance_by(&mut self, n: usize) -> Result<(), usize>
fn advance_by(&mut self, n: usize) -> Result<(), usize>
iter_advance_by
)n
elements. Read more1.0.0 · source§fn nth(&mut self, n: usize) -> Option<Self::Item>
fn nth(&mut self, n: usize) -> Option<Self::Item>
n
th element of the iterator. Read more1.28.0 · source§fn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
fn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
1.0.0 · source§fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where
Self: Sized,
U: IntoIterator<Item = Self::Item>,
fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>where
Self: Sized,
U: IntoIterator<Item = Self::Item>,
1.0.0 · source§fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where
Self: Sized,
U: IntoIterator,
fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where
Self: Sized,
U: IntoIterator,
source§fn intersperse_with<G>(self, separator: G) -> IntersperseWith<Self, G>where
Self: Sized,
G: FnMut() -> Self::Item,
fn intersperse_with<G>(self, separator: G) -> IntersperseWith<Self, G>where
Self: Sized,
G: FnMut() -> Self::Item,
iter_intersperse
)separator
between adjacent items of the original iterator. Read more1.0.0 · source§fn map<B, F>(self, f: F) -> Map<Self, F>where
Self: Sized,
F: FnMut(Self::Item) -> B,
fn map<B, F>(self, f: F) -> Map<Self, F>where
Self: Sized,
F: FnMut(Self::Item) -> B,
1.21.0 · source§fn for_each<F>(self, f: F)where
Self: Sized,
F: FnMut(Self::Item),
fn for_each<F>(self, f: F)where
Self: Sized,
F: FnMut(Self::Item),
1.0.0 · source§fn filter<P>(self, predicate: P) -> Filter<Self, P>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn filter<P>(self, predicate: P) -> Filter<Self, P>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
1.0.0 · source§fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>where
Self: Sized,
F: FnMut(Self::Item) -> Option<B>,
fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>where
Self: Sized,
F: FnMut(Self::Item) -> Option<B>,
1.0.0 · source§fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
1.0.0 · source§fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
1.0.0 · source§fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
1.57.0 · source§fn map_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where
Self: Sized,
P: FnMut(Self::Item) -> Option<B>,
fn map_while<B, P>(self, predicate: P) -> MapWhile<Self, P>where
Self: Sized,
P: FnMut(Self::Item) -> Option<B>,
1.0.0 · source§fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
n
elements. Read more1.0.0 · source§fn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where
Self: Sized,
n
elements, or fewer
if the underlying iterator ends sooner. Read more1.0.0 · source§fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>where
Self: Sized,
F: FnMut(&mut St, Self::Item) -> Option<B>,
fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>where
Self: Sized,
F: FnMut(&mut St, Self::Item) -> Option<B>,
1.0.0 · source§fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where
Self: Sized,
U: IntoIterator,
F: FnMut(Self::Item) -> U,
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where
Self: Sized,
U: IntoIterator,
F: FnMut(Self::Item) -> U,
1.0.0 · source§fn inspect<F>(self, f: F) -> Inspect<Self, F>where
Self: Sized,
F: FnMut(&Self::Item),
fn inspect<F>(self, f: F) -> Inspect<Self, F>where
Self: Sized,
F: FnMut(&Self::Item),
1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
1.0.0 · source§fn collect<B>(self) -> Bwhere
B: FromIterator<Self::Item>,
Self: Sized,
fn collect<B>(self) -> Bwhere
B: FromIterator<Self::Item>,
Self: Sized,
source§fn collect_into<E>(self, collection: &mut E) -> &mut Ewhere
E: Extend<Self::Item>,
Self: Sized,
fn collect_into<E>(self, collection: &mut E) -> &mut Ewhere
E: Extend<Self::Item>,
Self: Sized,
iter_collect_into
)1.0.0 · source§fn partition<B, F>(self, f: F) -> (B, B)where
Self: Sized,
B: Default + Extend<Self::Item>,
F: FnMut(&Self::Item) -> bool,
fn partition<B, F>(self, f: F) -> (B, B)where
Self: Sized,
B: Default + Extend<Self::Item>,
F: FnMut(&Self::Item) -> bool,
source§fn is_partitioned<P>(self, predicate: P) -> boolwhere
Self: Sized,
P: FnMut(Self::Item) -> bool,
fn is_partitioned<P>(self, predicate: P) -> boolwhere
Self: Sized,
P: FnMut(Self::Item) -> bool,
iter_is_partitioned
)true
precede all those that return false
. Read more1.27.0 · source§fn try_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere
Self: Sized,
F: FnMut(B, Self::Item) -> R,
R: Try<Output = B>,
fn try_fold<B, F, R>(&mut self, init: B, f: F) -> Rwhere
Self: Sized,
F: FnMut(B, Self::Item) -> R,
R: Try<Output = B>,
1.27.0 · source§fn try_for_each<F, R>(&mut self, f: F) -> Rwhere
Self: Sized,
F: FnMut(Self::Item) -> R,
R: Try<Output = ()>,
fn try_for_each<F, R>(&mut self, f: F) -> Rwhere
Self: Sized,
F: FnMut(Self::Item) -> R,
R: Try<Output = ()>,
1.0.0 · source§fn fold<B, F>(self, init: B, f: F) -> Bwhere
Self: Sized,
F: FnMut(B, Self::Item) -> B,
fn fold<B, F>(self, init: B, f: F) -> Bwhere
Self: Sized,
F: FnMut(B, Self::Item) -> B,
1.51.0 · source§fn reduce<F>(self, f: F) -> Option<Self::Item>where
Self: Sized,
F: FnMut(Self::Item, Self::Item) -> Self::Item,
fn reduce<F>(self, f: F) -> Option<Self::Item>where
Self: Sized,
F: FnMut(Self::Item, Self::Item) -> Self::Item,
source§fn try_reduce<F, R>(
&mut self,
f: F
) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere
Self: Sized,
F: FnMut(Self::Item, Self::Item) -> R,
R: Try<Output = Self::Item>,
<R as Try>::Residual: Residual<Option<Self::Item>>,
fn try_reduce<F, R>(
&mut self,
f: F
) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryTypewhere
Self: Sized,
F: FnMut(Self::Item, Self::Item) -> R,
R: Try<Output = Self::Item>,
<R as Try>::Residual: Residual<Option<Self::Item>>,
iterator_try_reduce
)1.0.0 · source§fn all<F>(&mut self, f: F) -> boolwhere
Self: Sized,
F: FnMut(Self::Item) -> bool,
fn all<F>(&mut self, f: F) -> boolwhere
Self: Sized,
F: FnMut(Self::Item) -> bool,
1.0.0 · source§fn any<F>(&mut self, f: F) -> boolwhere
Self: Sized,
F: FnMut(Self::Item) -> bool,
fn any<F>(&mut self, f: F) -> boolwhere
Self: Sized,
F: FnMut(Self::Item) -> bool,
1.0.0 · source§fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn find<P>(&mut self, predicate: P) -> Option<Self::Item>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
1.30.0 · source§fn find_map<B, F>(&mut self, f: F) -> Option<B>where
Self: Sized,
F: FnMut(Self::Item) -> Option<B>,
fn find_map<B, F>(&mut self, f: F) -> Option<B>where
Self: Sized,
F: FnMut(Self::Item) -> Option<B>,
source§fn try_find<F, R>(
&mut self,
f: F
) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere
Self: Sized,
F: FnMut(&Self::Item) -> R,
R: Try<Output = bool>,
<R as Try>::Residual: Residual<Option<Self::Item>>,
fn try_find<F, R>(
&mut self,
f: F
) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryTypewhere
Self: Sized,
F: FnMut(&Self::Item) -> R,
R: Try<Output = bool>,
<R as Try>::Residual: Residual<Option<Self::Item>>,
try_find
)1.0.0 · source§fn position<P>(&mut self, predicate: P) -> Option<usize>where
Self: Sized,
P: FnMut(Self::Item) -> bool,
fn position<P>(&mut self, predicate: P) -> Option<usize>where
Self: Sized,
P: FnMut(Self::Item) -> bool,
1.6.0 · source§fn max_by_key<B, F>(self, f: F) -> Option<Self::Item>where
B: Ord,
Self: Sized,
F: FnMut(&Self::Item) -> B,
fn max_by_key<B, F>(self, f: F) -> Option<Self::Item>where
B: Ord,
Self: Sized,
F: FnMut(&Self::Item) -> B,
1.15.0 · source§fn max_by<F>(self, compare: F) -> Option<Self::Item>where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
fn max_by<F>(self, compare: F) -> Option<Self::Item>where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
1.6.0 · source§fn min_by_key<B, F>(self, f: F) -> Option<Self::Item>where
B: Ord,
Self: Sized,
F: FnMut(&Self::Item) -> B,
fn min_by_key<B, F>(self, f: F) -> Option<Self::Item>where
B: Ord,
Self: Sized,
F: FnMut(&Self::Item) -> B,
1.15.0 · source§fn min_by<F>(self, compare: F) -> Option<Self::Item>where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
fn min_by<F>(self, compare: F) -> Option<Self::Item>where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
1.0.0 · source§fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where
FromA: Default + Extend<A>,
FromB: Default + Extend<B>,
Self: Sized + Iterator<Item = (A, B)>,
fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)where
FromA: Default + Extend<A>,
FromB: Default + Extend<B>,
Self: Sized + Iterator<Item = (A, B)>,
1.36.0 · source§fn copied<'a, T>(self) -> Copied<Self>where
T: 'a + Copy,
Self: Sized + Iterator<Item = &'a T>,
fn copied<'a, T>(self) -> Copied<Self>where
T: 'a + Copy,
Self: Sized + Iterator<Item = &'a T>,
1.0.0 · source§fn cloned<'a, T>(self) -> Cloned<Self>where
T: 'a + Clone,
Self: Sized + Iterator<Item = &'a T>,
fn cloned<'a, T>(self) -> Cloned<Self>where
T: 'a + Clone,
Self: Sized + Iterator<Item = &'a T>,
source§fn array_chunks<const N: usize>(self) -> ArrayChunks<Self, N>where
Self: Sized,
fn array_chunks<const N: usize>(self) -> ArrayChunks<Self, N>where
Self: Sized,
iter_array_chunks
)N
elements of the iterator at a time. Read more1.11.0 · source§fn sum<S>(self) -> Swhere
Self: Sized,
S: Sum<Self::Item>,
fn sum<S>(self) -> Swhere
Self: Sized,
S: Sum<Self::Item>,
1.11.0 · source§fn product<P>(self) -> Pwhere
Self: Sized,
P: Product<Self::Item>,
fn product<P>(self) -> Pwhere
Self: Sized,
P: Product<Self::Item>,
source§fn cmp_by<I, F>(self, other: I, cmp: F) -> Orderingwhere
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Ordering,
fn cmp_by<I, F>(self, other: I, cmp: F) -> Orderingwhere
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Ordering,
iter_order_by
)Iterator
with those
of another with respect to the specified comparison function. Read more1.5.0 · source§fn partial_cmp<I>(self, other: I) -> Option<Ordering>where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
fn partial_cmp<I>(self, other: I) -> Option<Ordering>where
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
source§fn partial_cmp_by<I, F>(self, other: I, partial_cmp: F) -> Option<Ordering>where
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Option<Ordering>,
fn partial_cmp_by<I, F>(self, other: I, partial_cmp: F) -> Option<Ordering>where
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Option<Ordering>,
iter_order_by
)Iterator
with those
of another with respect to the specified comparison function. Read more1.5.0 · source§fn eq<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
Self: Sized,
fn eq<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
Self: Sized,
source§fn eq_by<I, F>(self, other: I, eq: F) -> boolwhere
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> bool,
fn eq_by<I, F>(self, other: I, eq: F) -> boolwhere
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> bool,
iter_order_by
)1.5.0 · source§fn ne<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
Self: Sized,
fn ne<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialEq<<I as IntoIterator>::Item>,
Self: Sized,
1.5.0 · source§fn lt<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
fn lt<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
Iterator
are lexicographically
less than those of another. Read more1.5.0 · source§fn le<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
fn le<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
Iterator
are lexicographically
less or equal to those of another. Read more1.5.0 · source§fn gt<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
fn gt<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
Iterator
are lexicographically
greater than those of another. Read more1.5.0 · source§fn ge<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
fn ge<I>(self, other: I) -> boolwhere
I: IntoIterator,
Self::Item: PartialOrd<<I as IntoIterator>::Item>,
Self: Sized,
Iterator
are lexicographically
greater than or equal to those of another. Read moresource§fn is_sorted_by<F>(self, compare: F) -> boolwhere
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
fn is_sorted_by<F>(self, compare: F) -> boolwhere
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
is_sorted
)source§fn is_sorted_by_key<F, K>(self, f: F) -> boolwhere
Self: Sized,
F: FnMut(Self::Item) -> K,
K: PartialOrd<K>,
fn is_sorted_by_key<F, K>(self, f: F) -> boolwhere
Self: Sized,
F: FnMut(Self::Item) -> K,
K: PartialOrd<K>,
is_sorted
)Auto Trait Implementations§
impl<R> !RefUnwindSafe for ReadEncPulseIter<R>
impl<R> Send for ReadEncPulseIter<R>where
R: Send,
impl<R> Sync for ReadEncPulseIter<R>where
R: Sync,
impl<R> Unpin for ReadEncPulseIter<R>where
R: Unpin,
impl<R> !UnwindSafe for ReadEncPulseIter<R>
Blanket Implementations§
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
source§impl<I> IntoIterator for Iwhere
I: Iterator,
impl<I> IntoIterator for Iwhere
I: Iterator,
source§impl<S, T> IntoSample<S> for Twhere
S: FromSample<T>,
impl<S, T> IntoSample<S> for Twhere
S: FromSample<T>,
source§fn into_sample(self) -> S
fn into_sample(self) -> S
S
a sample type from self
.source§impl<I> IteratorRandom for Iwhere
I: Iterator,
impl<I> IteratorRandom for Iwhere
I: Iterator,
source§fn choose<R>(self, rng: &mut R) -> Option<Self::Item>where
R: Rng + ?Sized,
fn choose<R>(self, rng: &mut R) -> Option<Self::Item>where
R: Rng + ?Sized,
source§fn choose_stable<R>(self, rng: &mut R) -> Option<Self::Item>where
R: Rng + ?Sized,
fn choose_stable<R>(self, rng: &mut R) -> Option<Self::Item>where
R: Rng + ?Sized,
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds. Read more§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
.tap_borrow()
only in debug builds, and is erased in release
builds. Read more§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
.tap_borrow_mut()
only in debug builds, and is erased in release
builds. Read more§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
.tap_ref()
only in debug builds, and is erased in release
builds. Read more§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
.tap_ref_mut()
only in debug builds, and is erased in release
builds. Read more