Struct brainfoamkit_lib::MockReader
source · pub struct MockReader {
pub data: Cursor<Vec<u8>>,
}
Expand description
The MockReader
struct
This struct is used to implement a mock Reader
for the VirtualMachine
.
This allows for us to test the VirtualMachine
without having to use
Stdin
or File
as the Reader
.
This struct is used for testing purposes only, and should not be used in production code.
Examples
use brainfoamkit_lib::VMReader;
let mut mock = brainfoamkit_lib::MockReader {
data: std::io::Cursor::new("A".as_bytes().to_vec()),
};
assert_eq!(mock.read().unwrap(), 65);
See Also
Fields§
§data: Cursor<Vec<u8>>
Trait Implementations§
source§impl Debug for MockReader
impl Debug for MockReader
source§impl Default for MockReader
impl Default for MockReader
source§fn default() -> MockReader
fn default() -> MockReader
Returns the “default value” for a type. Read more
source§impl VMReader for MockReader
impl VMReader for MockReader
The implementation of the VMReader
trait for the MockReader
struct
source§fn read(&mut self) -> Result<u8>
fn read(&mut self) -> Result<u8>
Read a single byte from the mock reader
This function reads a single byte from the mock reader and returns it as
a u8
for use by the VirtualMachine
. The mock reader is
implemented using a Cursor<Vec<u8>>
, which is used to store the data
that is read from the mock reader.
Errors
This function will return an error if the byte read from the mock reader is not within the ASCII range.
Examples
use brainfoamkit_lib::VMReader;
let mut mock = brainfoamkit_lib::MockReader {
data: std::io::Cursor::new("A".as_bytes().to_vec()),
};
assert_eq!(mock.read().unwrap(), 65);
assert_eq!(
mock.get_vmreader_type(),
brainfoamkit_lib::VMReaderType::Mock
);
source§fn get_vmreader_type(&self) -> VMReaderType
fn get_vmreader_type(&self) -> VMReaderType
Get the type of the reader Read more
Auto Trait Implementations§
impl RefUnwindSafe for MockReader
impl Send for MockReader
impl Sync for MockReader
impl Unpin for MockReader
impl UnwindSafe for MockReader
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
Mutably borrows from an owned value. Read more