diff --git a/haversine/src/distance.rs b/haversine/src/distance.rs index 68e5d96..1a5fbf1 100644 --- a/haversine/src/distance.rs +++ b/haversine/src/distance.rs @@ -4,6 +4,7 @@ fn square(x: f64) -> f64 { x * x } +#[must_use] pub fn naive(point: &CoordinatePair, earth_radius: f64) -> f64 { let lat1 = point.y0; let lat2 = point.y1; diff --git a/json/src/json_object.rs b/json/src/json_object.rs index 20ee2d1..82ef979 100644 --- a/json/src/json_object.rs +++ b/json/src/json_object.rs @@ -350,6 +350,7 @@ where } impl JsonValue { + #[must_use] pub fn as_number(&self) -> f64 { match self { JsonValue::Number(f) => *f, @@ -357,6 +358,7 @@ impl JsonValue { } } + #[must_use] pub fn as_object(&self) -> &HashMap { match self { JsonValue::Object(o) => &o.values, @@ -364,6 +366,7 @@ impl JsonValue { } } + #[must_use] pub fn as_array(&self) -> &Vec { match self { JsonValue::Array(a) => a, diff --git a/sim_8086/src/arithmetic_instruction.rs b/sim_8086/src/arithmetic_instruction.rs index 1b4d3ba..aca3f63 100644 --- a/sim_8086/src/arithmetic_instruction.rs +++ b/sim_8086/src/arithmetic_instruction.rs @@ -90,6 +90,7 @@ impl ArithmeticInstruction { (s as u8) * 8 + d * 2 + if is_wide { 1 } else { 0 } } + #[must_use] pub fn to_bytes(&self) -> Vec { let mut result = Vec::::with_capacity(2); match &self.instruction { @@ -187,6 +188,7 @@ impl ArithmeticInstruction { } } + #[must_use] pub fn clock_count(&self) -> (u32, String) { match self.op { ArithmeticOperation::Sub @@ -299,6 +301,7 @@ impl Display for ArithmeticOperation { } impl ArithmeticOperation { + #[must_use] pub const fn of_byte(x: u8) -> ArithmeticOperation { match x { 0 => ArithmeticOperation::Add, diff --git a/sim_8086/src/boolean_instruction.rs b/sim_8086/src/boolean_instruction.rs index f497be8..037dc0c 100644 --- a/sim_8086/src/boolean_instruction.rs +++ b/sim_8086/src/boolean_instruction.rs @@ -73,6 +73,7 @@ impl Display for BooleanInstruction { } impl BooleanInstruction { + #[must_use] pub fn to_bytes(&self) -> Vec { match &self.dest { /* @@ -154,6 +155,7 @@ impl BooleanInstruction { } } + #[must_use] pub fn length(&self) -> u8 { match &self.dest { BooleanInstructionDestination::ImmediateToAcc(data) => match data { @@ -164,6 +166,7 @@ impl BooleanInstruction { } } + #[must_use] pub fn clock_count(&self) -> (u32, String) { match self.selection { BooleanInstructionType::Test => match self.dest { diff --git a/sim_8086/src/computer.rs b/sim_8086/src/computer.rs index 8ad0135..6f4fe7f 100644 --- a/sim_8086/src/computer.rs +++ b/sim_8086/src/computer.rs @@ -52,6 +52,7 @@ pub struct Registers { } impl Registers { + #[must_use] pub fn diff(&self, old: &Registers) -> String { let mut result = Vec::new(); @@ -264,6 +265,7 @@ struct ResultFlags { impl Computer { #[allow(clippy::new_without_default)] + #[must_use] pub fn new() -> Computer { Computer { memory: [0; 65536], @@ -291,6 +293,7 @@ impl Computer { self.flags.set(f, v) } + #[must_use] pub fn dump_flag_state(&self) -> String { format!("{}", self.flags) } @@ -1307,6 +1310,7 @@ impl Computer { ) } + #[must_use] pub fn get_program_counter(&self) -> u16 { self.program_counter } @@ -1432,6 +1436,7 @@ impl Computer { } } + #[must_use] pub fn dump_register_state(&self) -> String { let mut result = "".to_owned(); for r in [ diff --git a/sim_8086/src/inc_instruction.rs b/sim_8086/src/inc_instruction.rs index f15617c..0ab9dc9 100644 --- a/sim_8086/src/inc_instruction.rs +++ b/sim_8086/src/inc_instruction.rs @@ -19,15 +19,18 @@ impl Display for IncInstruction { } impl IncInstruction { + #[must_use] pub fn to_bytes(&self) -> Vec { let (id, _is_wide) = self.target.to_id(); vec![0b01000000 + id + if self.is_inc { 0 } else { 8 }] } + #[must_use] pub fn length(&self) -> u8 { 1 } + #[must_use] pub fn clock_count(&self) -> (u32, String) { if self.target.is_wide() { (2, "".to_owned()) diff --git a/sim_8086/src/instruction.rs b/sim_8086/src/instruction.rs index 8496a76..1ba8b4b 100644 --- a/sim_8086/src/instruction.rs +++ b/sim_8086/src/instruction.rs @@ -60,6 +60,7 @@ where } impl<'a> Instruction<&'a str> { + #[must_use] pub fn to_bytes(&self) -> Vec { match self { Instruction::Move(mov) => mov.to_bytes(), @@ -104,6 +105,7 @@ impl<'a> Instruction<&'a str> { } impl Instruction { + #[must_use] pub fn to_bytes(&self) -> Vec { match self { Instruction::Move(mov) => mov.to_bytes(), diff --git a/sim_8086/src/jump_instruction.rs b/sim_8086/src/jump_instruction.rs index 82515ab..7cdc490 100644 --- a/sim_8086/src/jump_instruction.rs +++ b/sim_8086/src/jump_instruction.rs @@ -54,6 +54,7 @@ impl Display for Jump { } impl Jump { + #[must_use] pub fn clock_count(&self, is_success: bool) -> u32 { match self { Jump::Jle diff --git a/sim_8086/src/logic_instruction.rs b/sim_8086/src/logic_instruction.rs index ea32cb6..f693490 100644 --- a/sim_8086/src/logic_instruction.rs +++ b/sim_8086/src/logic_instruction.rs @@ -65,6 +65,7 @@ impl Display for LogicInstruction { } impl LogicInstruction { + #[must_use] pub fn length(&self) -> u8 { match &self.target { LogicTarget::Register(_) => 2, @@ -72,6 +73,7 @@ impl LogicInstruction { } } + #[must_use] pub fn to_bytes(&self) -> Vec { let mut result = Vec::new(); let byte = match self.op { @@ -103,6 +105,7 @@ impl LogicInstruction { result } + #[must_use] pub fn clock_count(&self) -> (u32, String) { match (&self.op, &self.target) { (LogicInstructionType::Not, LogicTarget::Register(_)) => (3, "".to_owned()), diff --git a/sim_8086/src/move_instruction.rs b/sim_8086/src/move_instruction.rs index 4850d31..e1592c9 100644 --- a/sim_8086/src/move_instruction.rs +++ b/sim_8086/src/move_instruction.rs @@ -472,6 +472,7 @@ impl MoveInstruction { } } + #[must_use] pub fn clock_count(&self) -> (u32, String) { match self { MoveInstruction::RegRegMove(_) => (2, "".to_owned()), diff --git a/sim_8086/src/register.rs b/sim_8086/src/register.rs index 1fc8662..631a674 100644 --- a/sim_8086/src/register.rs +++ b/sim_8086/src/register.rs @@ -11,6 +11,7 @@ pub enum GeneralRegister { } impl GeneralRegister { + #[must_use] pub const fn to_id(&self) -> u8 { match self { GeneralRegister::A => 0b00, @@ -20,6 +21,7 @@ impl GeneralRegister { } } + #[must_use] pub const fn of_id(id: u8) -> GeneralRegister { match id { 0 => GeneralRegister::A, @@ -51,6 +53,7 @@ pub enum SpecialRegister { } impl SpecialRegister { + #[must_use] pub const fn to_id(&self) -> u8 { // These are all wide. 4 + match self { @@ -61,6 +64,7 @@ impl SpecialRegister { } } + #[must_use] pub const fn of_id(id: u8) -> SpecialRegister { match id { 4 => SpecialRegister::StackPointer, @@ -125,6 +129,7 @@ impl Display for SegmentRegister { } impl SegmentRegister { + #[must_use] pub const fn of_byte(b: u8) -> SegmentRegister { match b { 0 => SegmentRegister::Extra, @@ -152,6 +157,7 @@ impl Display for Register { } impl Register { + #[must_use] pub const fn of_id(id: u8, is_wide: bool) -> Register { if is_wide { if id >= 4 { @@ -173,6 +179,7 @@ impl Register { } // Returns true if the result is wide. + #[must_use] pub const fn to_id(self: &Register) -> (u8, bool) { match self { Register::Special(s) => (s.to_id(), true), @@ -184,6 +191,7 @@ impl Register { } } + #[must_use] pub const fn is_wide(self: &Register) -> bool { match self { Register::Special(_) => true,