diff options
Diffstat (limited to '')
| -rw-r--r-- | crates/brainf_rs/src/engine.rs (renamed from src/engine.rs) | 28 |
1 files changed, 4 insertions, 24 deletions
diff --git a/src/engine.rs b/crates/brainf_rs/src/engine.rs index 3269dff..e60acaa 100644 --- a/src/engine.rs +++ b/crates/brainf_rs/src/engine.rs @@ -3,11 +3,7 @@ //! This predominantly allows implementation of a [`u16`] executor. #[cfg(feature = "bigint-engine")] -use std::io::Cursor; -use std::io::Read; - -#[cfg(feature = "bigint-engine")] -use byteorder::{BigEndian, ReadBytesExt}; +use byteorder::{NativeEndian, ReadBytesExt}; use num_traits::{One, Unsigned, WrappingAdd, WrappingSub, Zero}; use thiserror::Error; @@ -55,11 +51,7 @@ impl Engine for executor::U8 { type TapeInner = u8; fn read_byte() -> Result<u8, Error> { - let mut input: [u8; 1] = [0; 1]; - - std::io::stdin().read_exact(&mut input)?; - - Ok(input[0]) + Ok(std::io::stdin().read_u8()?) } fn write_byte(byte: u8) -> Result<(), Error> { @@ -74,13 +66,7 @@ impl Engine for executor::U16 { type TapeInner = u16; fn read_byte() -> Result<u16, Error> { - let mut input: [u8; 2] = [0; 2]; - - std::io::stdin().read_exact(&mut input)?; - - let mut reader = Cursor::new(input); - - Ok(reader.read_u16::<BigEndian>()?) + Ok(std::io::stdin().read_u16::<NativeEndian>()?) } fn write_byte(byte: u16) -> Result<(), Error> { @@ -98,13 +84,7 @@ impl Engine for executor::U32 { type TapeInner = u32; fn read_byte() -> Result<u32, Error> { - let mut input: [u8; 4] = [0; 4]; - - std::io::stdin().read_exact(&mut input)?; - - let mut reader = Cursor::new(input); - - Ok(reader.read_u32::<BigEndian>()?) + Ok(std::io::stdin().read_u32::<NativeEndian>()?) } fn write_byte(byte: u32) -> Result<(), Error> { |