pub struct Tape<F> {
pub running: bool,
pub tap: Option<Tap<F>>,
}Expand description
The struct that emulates a simple tape recorder.
Fields§
§running: booltrue if the tape is playing, depending on the Tap variant it may indicate tape playback or recording.
false then the tape has stopped.
tap: Option<Tap<F>>Some(tap) indicates the tape cassette is inserted, None - there is no tape.
Implementations§
Source§impl<F: Write + Read + Seek> Tape<F>
impl<F: Write + Read + Seek> Tape<F>
Sourcepub fn new_with_tape(file: F) -> Self
pub fn new_with_tape(file: F) -> Self
Returns a new instance of Tape with the tape file inserted.
Sourcepub fn insert_as_reader(&mut self, file: F) -> Option<Tap<F>>
pub fn insert_as_reader(&mut self, file: F) -> Option<Tap<F>>
Inserts the tape file as a Tap::Reader. Returns the previously inserted Tap instance.
Sourcepub fn try_insert_as_writer(&mut self, file: F) -> Result<Option<Tap<F>>>
pub fn try_insert_as_writer(&mut self, file: F) -> Result<Option<Tap<F>>>
Tries to insert the tape file as a Tap::Writer. Returns the previously inserted Tap instance.
Sourcepub fn eject(&mut self) -> Option<Tap<F>>
pub fn eject(&mut self) -> Option<Tap<F>>
Ejects and returns the previously inserted Tap instance.
Sourcepub fn make_reader(&mut self) -> Result<bool>
pub fn make_reader(&mut self) -> Result<bool>
Transforms the inserted Tap into the Tap::Reader on success.
Returns Ok(true) if the inserted Tap was a Tap::Writer. In this instance, the cursor
position of the reader is set to the beginning of a file and this method ensures that
the chunk being currently written is comitted thus ensuring the integrity of the TAP
file and also calls the Write::flush on the file before transforming it.
If the inserted Tap is already a Tap::Reader or if there is no Tap inserted returns
Ok(false).
Sourcepub fn make_writer(&mut self) -> Result<bool>
pub fn make_writer(&mut self) -> Result<bool>
Transforms the inserted Tap into the Tap::Writer on success.
Returns Ok(true) if the inserted Tap was a Tap::Reader. In this instance the cursor
position of the reader is set to the end of a file.
If the inserted Tap is already a Tap::Writer or if there is no Tap inserted returns
Ok(false).
Sourcepub fn is_ejected(&self) -> bool
pub fn is_ejected(&self) -> bool
Returns true if there is no Tap inserted, otherwise returns false.
Sourcepub fn is_inserted(&self) -> bool
pub fn is_inserted(&self) -> bool
Returns true if there is a Tap inserted, otherwise returns false.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Returns true if there is some Tap inserted and Tape::running is true, otherwise returns false.
Sourcepub fn is_idle(&self) -> bool
pub fn is_idle(&self) -> bool
Returns true if no Tap is inserted or Tape::running is false, otherwise returns true.
Sourcepub fn tap_state(&self) -> TapState
pub fn tap_state(&self) -> TapState
Returns the current status of the inserted tape as an enum.
Sourcepub fn is_playing(&self) -> bool
pub fn is_playing(&self) -> bool
Returns true if there is a Tap::Reader variant inserted and Tape::running is true,
otherwise returns false.
Sourcepub fn is_recording(&self) -> bool
pub fn is_recording(&self) -> bool
Returns true if there is a Tap::Writer variant inserted and Tape::running is true,
otherwise returns false.
Sourcepub fn reader_mut(&mut self) -> Option<&mut TapChunkPulseIter<F>>
pub fn reader_mut(&mut self) -> Option<&mut TapChunkPulseIter<F>>
Returns a mutable reference to the pulse iterator if the current variant of Tape::tap is Tap::Reader.
Sourcepub fn writer_mut(&mut self) -> Option<&mut TapChunkWriter<F>>
pub fn writer_mut(&mut self) -> Option<&mut TapChunkWriter<F>>
Returns a mutable reference to the tap chunk writer if the current variant of Tape::tap is Tap::Writer.
Sourcepub fn reader_ref(&self) -> Option<&TapChunkPulseIter<F>>
pub fn reader_ref(&self) -> Option<&TapChunkPulseIter<F>>
Returns a reference to the pulse iterator if the current variant of Tape::tap is Tap::Reader.
Sourcepub fn writer_ref(&self) -> Option<&TapChunkWriter<F>>
pub fn writer_ref(&self) -> Option<&TapChunkWriter<F>>
Returns a reference to the tap chunk writer if the current variant of Tape::tap is Tap::Writer.
Sourcepub fn playing_reader_mut(&mut self) -> Option<&mut TapChunkPulseIter<F>>
pub fn playing_reader_mut(&mut self) -> Option<&mut TapChunkPulseIter<F>>
Returns a mutable reference to the pulse iterator if there is a Tap::Reader variant inserted
and Tape::running is true, otherwise returns None.
Sourcepub fn recording_writer_mut(&mut self) -> Option<&mut TapChunkWriter<F>>
pub fn recording_writer_mut(&mut self) -> Option<&mut TapChunkWriter<F>>
Returns a mutable reference to the tap chunk writer if there is a Tap::Writer variant inserted
and Tape::running is true, otherwise returns None.
Sourcepub fn try_reader_mut(&mut self) -> Result<Option<TapChunkReaderMut<'_, F>>>
pub fn try_reader_mut(&mut self) -> Result<Option<TapChunkReaderMut<'_, F>>>
Returns a clone of TapChunkReader with a mutable reference to the file under the guard that ensures the position of the underlying file is set back to where it was before this method was called when the guard goes out of scope.
Sourcepub fn play(&mut self) -> Result<bool>
pub fn play(&mut self) -> Result<bool>
Sets Tape::running to true and ensures the inserted variant is a Tap::Reader.
Returns Ok(true) if the state of self changes.
Sourcepub fn record(&mut self) -> Result<bool>
pub fn record(&mut self) -> Result<bool>
Sets Tape::running to true and ensures the inserted variant is a Tap::Writer.
Returns Ok(true) if the state of self changes.
Sourcepub fn stop(&mut self)
pub fn stop(&mut self)
Sets Tape::running to false.
Sourcepub fn rewind(&mut self) -> bool
pub fn rewind(&mut self) -> bool
Conditionally rewinds a tape if it’s inserted and its variant is Tap::Reader.
In this instance returns true. Otherwise returns false.
Sourcepub fn forward_chunk(&mut self) -> Result<Option<bool>>
pub fn forward_chunk(&mut self) -> Result<Option<bool>>
Conditionally forwards a tape to the next chunk if it’s inserted and its variant
is Tap::Reader. In this instance returns Ok(Some(was_next_chunk)). Otherwise returns
Ok(None).
Sourcepub fn rewind_prev_chunk(&mut self) -> Result<Option<u32>>
pub fn rewind_prev_chunk(&mut self) -> Result<Option<u32>>
Conditionally rewinds a tape to the previous chunk if it’s inserted and its variant
is Tap::Reader. In this instance returns Ok(Some(chunk_no)). Otherwise returns Ok(None).
Sourcepub fn rewind_chunk(&mut self) -> Result<Option<u32>>
pub fn rewind_chunk(&mut self) -> Result<Option<u32>>
Conditionally rewinds a tape to the beginning of the current chunk if it’s inserted and its
variant is Tap::Reader. In this instance returns Ok(Some(chunk_no)). Otherwise returns
Ok(None).
Sourcepub fn rewind_nth_chunk(&mut self, chunk_no: u32) -> Result<Option<bool>>
pub fn rewind_nth_chunk(&mut self, chunk_no: u32) -> Result<Option<bool>>
Conditionally rewinds or forwards a tape to the nth chunk if it’s inserted and its
variant is Tap::Reader. In this instance returns Ok(Some(was_a_chunk)). Otherwise
returns Ok(None).
Trait Implementations§
Auto Trait Implementations§
impl<F> Freeze for Tape<F>where
F: Freeze,
impl<F> !RefUnwindSafe for Tape<F>
impl<F> Send for Tape<F>where
F: Send,
impl<F> Sync for Tape<F>where
F: Sync,
impl<F> Unpin for Tape<F>where
F: Unpin,
impl<F> !UnwindSafe for Tape<F>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§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.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§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.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§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 moreSource§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 moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§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.Source§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.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.