Struct spectrusty_formats::tap::TapChunk
source · pub struct TapChunk<T> { /* private fields */ }
Expand description
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.
Implementations§
source§impl<T> TapChunk<T>
impl<T> TapChunk<T>
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Returns the underlying bytes container.
Examples found in repository?
816 817 818 819 820 821 822 823 824 825 826 827 828
pub fn into_pulse_iter(self) -> ReadEncPulseIter<Cursor<T>> {
ReadEncPulseIter::new(Cursor::new(self.into_inner()))
}
/// Creates a new TapChunk with a specified storage, possibly cloning the data
/// unless the target storage can be converted to without cloning,
/// e.g. `Vec<u8> <=> Box<[u8]>`.
pub fn with_storage<D>(self) -> TapChunk<D>
where D: From<T> + AsRef<[u8]>
{
let data = D::from(self.into_inner());
TapChunk::<D>::from(data)
}
source§impl<T> TapChunk<T>where
T: AsRef<[u8]>,
impl<T> TapChunk<T>where
T: AsRef<[u8]>,
sourcepub fn info(&self) -> Result<TapChunkInfo>
pub fn info(&self) -> Result<TapChunkInfo>
Attempts to create an instance of TapChunkInfo from underlying data.
sourcepub fn is_head(&self) -> bool
pub fn is_head(&self) -> bool
Checks if this TAP chunk is a Header block.
Examples found in repository?
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
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
}
sourcepub fn validated(self) -> Result<Self>
pub fn validated(self) -> Result<Self>
Validates if this TAP chunk is a valid data or Header block returning self
on success.
sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validates if this TAP chunk is a valid data or Header block.
sourcepub fn data(&self) -> Option<&[u8]>
pub fn data(&self) -> Option<&[u8]>
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.
sourcepub fn data_block_len(&self) -> Option<u16>
pub fn data_block_len(&self) -> Option<u16>
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.
sourcepub fn start(&self) -> Option<u16>
pub fn start(&self) -> Option<u16>
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.
sourcepub fn vars(&self) -> Option<u16>
pub fn vars(&self) -> Option<u16>
Returns an offset to VARS
only if the underlying bytes represents the Header block.
Only valid for headers with BlockType::Program.
sourcepub fn array_name(&self) -> Option<char>
pub fn array_name(&self) -> Option<char>
Returns an array variable name only if the underlying bytes represents the Header block.
Only valid for headers with BlockType::CharArray or BlockType::NumberArray.
sourcepub fn block_type(&self) -> Option<BlockType>
pub fn block_type(&self) -> Option<BlockType>
Returns a next chunk’s data type only if the underlying bytes represents the Header block.
sourcepub fn as_pulse_iter(&self) -> ReadEncPulseIter<Cursor<&[u8]>> ⓘ
pub fn as_pulse_iter(&self) -> ReadEncPulseIter<Cursor<&[u8]>> ⓘ
Returns a pulse interval iterator referencing this TAP chunk.
sourcepub fn into_pulse_iter(self) -> ReadEncPulseIter<Cursor<T>> ⓘ
pub fn into_pulse_iter(self) -> ReadEncPulseIter<Cursor<T>> ⓘ
Converts this TAP chunk into a pulse interval iterator owning this chunk’s data.
Trait Implementations§
impl<T: Copy> Copy for TapChunk<T>
Auto Trait Implementations§
impl<T> RefUnwindSafe for TapChunk<T>where
T: RefUnwindSafe,
impl<T> Send for TapChunk<T>where
T: Send,
impl<T> Sync for TapChunk<T>where
T: Sync,
impl<T> Unpin for TapChunk<T>where
T: Unpin,
impl<T> UnwindSafe for TapChunk<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<A, T> AsMutBits<T> for Awhere
A: AsMut<[T]>,
T: BitStore,
impl<A, T> AsMutBits<T> for Awhere
A: AsMut<[T]>,
T: BitStore,
§fn as_mut_bits<O>(&mut self) -> &mut BitSlice<T, O> ⓘwhere
O: BitOrder,
fn as_mut_bits<O>(&mut self) -> &mut BitSlice<T, O> ⓘwhere
O: BitOrder,
self
as a mutable bit-slice region with the O
ordering.§fn try_as_mut_bits<O>(&mut self) -> Result<&mut BitSlice<T, O>, BitSpanError<T>>where
O: BitOrder,
fn try_as_mut_bits<O>(&mut self) -> Result<&mut BitSlice<T, O>, BitSpanError<T>>where
O: BitOrder,
§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<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
.§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