Minor code cleanup.
This commit is contained in:
parent
ca91c2ea56
commit
f522eab9bf
|
@ -1,5 +1,4 @@
|
|||
use std::collections::VecDeque;
|
||||
use std::fmt::Formatter;
|
||||
use std::{cmp, fmt};
|
||||
|
||||
fn capitalise(s: &str) -> String {
|
||||
|
@ -98,7 +97,7 @@ impl Default for BasicRegister {
|
|||
}
|
||||
|
||||
impl fmt::Display for BasicRegister {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "Memory: [")?;
|
||||
|
||||
for (count, v) in self.memory.iter().enumerate() {
|
||||
|
@ -113,7 +112,7 @@ impl fmt::Display for BasicRegister {
|
|||
}
|
||||
|
||||
impl fmt::Binary for BasicRegister {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "Memory: ")?;
|
||||
|
||||
for v in self.memory.iter() {
|
||||
|
@ -152,7 +151,7 @@ fn read_vec(variable_name: &str) -> Vec<char> {
|
|||
pub fn char_to_bool_vecdeque(char_vector: Vec<char>) -> VecDeque<bool> {
|
||||
let mut bool_vector: VecDeque<bool> = VecDeque::new();
|
||||
|
||||
for value in char_vector.iter() {
|
||||
for value in char_vector.into_iter() {
|
||||
match value {
|
||||
'0' => bool_vector.push_back(false),
|
||||
'1' => bool_vector.push_back(true),
|
||||
|
@ -165,7 +164,7 @@ pub fn char_to_bool_vecdeque(char_vector: Vec<char>) -> VecDeque<bool> {
|
|||
|
||||
/// Handles getting the memory for the register from the user.
|
||||
pub fn get_memory(variable_name: &str) -> VecDeque<bool> {
|
||||
char_to_bool_vector(read_vec(variable_name))
|
||||
char_to_bool_vecdeque(read_vec(variable_name))
|
||||
}
|
||||
|
||||
/// Aligns two registers by the length of the bigger one.
|
||||
|
@ -173,9 +172,7 @@ pub fn align_registers(
|
|||
mut first_register: BasicRegister,
|
||||
mut second_register: BasicRegister,
|
||||
) -> (BasicRegister, BasicRegister) {
|
||||
let first_size: usize = first_register.memory.len();
|
||||
let second_size: usize = second_register.memory.len();
|
||||
let required_size: usize = cmp::max(first_size, second_size);
|
||||
let required_size: usize = cmp::max(first_register.len(), second_register.len());
|
||||
|
||||
(
|
||||
first_register.adjusted_by_size(required_size),
|
||||
|
|
Loading…
Reference in New Issue