@@ -66,9 +66,9 @@ impl Display for InstructionType {
66
66
}
67
67
}
68
68
69
- impl InstructionType {
70
- pub fn from_u8 ( ins : u8 ) -> Self {
71
- Self :: from_str ( & ( ins as char ) . to_string ( ) ) . expect ( "Invalid instruction" )
69
+ impl From < u8 > for InstructionType {
70
+ fn from ( value : u8 ) -> Self {
71
+ Self :: from_str ( & ( value as char ) . to_string ( ) ) . expect ( "Invalid instruction" )
72
72
}
73
73
}
74
74
@@ -114,21 +114,21 @@ mod tests {
114
114
// Test from_u8 implementation
115
115
#[ test]
116
116
fn test_instruction_type_from_u8 ( ) {
117
- assert_eq ! ( InstructionType :: from_u8 ( b'>' ) , InstructionType :: Right ) ;
118
- assert_eq ! ( InstructionType :: from_u8 ( b'<' ) , InstructionType :: Left ) ;
119
- assert_eq ! ( InstructionType :: from_u8 ( b'+' ) , InstructionType :: Plus ) ;
120
- assert_eq ! ( InstructionType :: from_u8 ( b'-' ) , InstructionType :: Minus ) ;
121
- assert_eq ! ( InstructionType :: from_u8 ( b'.' ) , InstructionType :: PutChar ) ;
122
- assert_eq ! ( InstructionType :: from_u8 ( b',' ) , InstructionType :: ReadChar ) ;
123
- assert_eq ! ( InstructionType :: from_u8 ( b'[' ) , InstructionType :: JumpIfZero ) ;
124
- assert_eq ! ( InstructionType :: from_u8 ( b']' ) , InstructionType :: JumpIfNotZero ) ;
117
+ assert_eq ! ( InstructionType :: from ( b'>' ) , InstructionType :: Right ) ;
118
+ assert_eq ! ( InstructionType :: from ( b'<' ) , InstructionType :: Left ) ;
119
+ assert_eq ! ( InstructionType :: from ( b'+' ) , InstructionType :: Plus ) ;
120
+ assert_eq ! ( InstructionType :: from ( b'-' ) , InstructionType :: Minus ) ;
121
+ assert_eq ! ( InstructionType :: from ( b'.' ) , InstructionType :: PutChar ) ;
122
+ assert_eq ! ( InstructionType :: from ( b',' ) , InstructionType :: ReadChar ) ;
123
+ assert_eq ! ( InstructionType :: from ( b'[' ) , InstructionType :: JumpIfZero ) ;
124
+ assert_eq ! ( InstructionType :: from ( b']' ) , InstructionType :: JumpIfNotZero ) ;
125
125
}
126
126
127
127
// Test from_u8 with invalid input (should panic)
128
128
#[ test]
129
129
#[ should_panic( expected = "Invalid instruction" ) ]
130
130
fn test_instruction_type_from_u8_invalid ( ) {
131
- InstructionType :: from_u8 ( b'x' ) ;
131
+ let _ = InstructionType :: from ( b'x' ) ;
132
132
}
133
133
134
134
// Test Instruction struct creation
0 commit comments