@@ -5,8 +5,8 @@ use crate::error::{Error, Result};
55use crate :: memory:: GuestAddressSpaceViewMut ;
66use alloc:: boxed:: Box ;
77use alloc:: vec:: Vec ;
8- use core:: convert:: TryInto ;
9- use derive_try_from_primitive :: TryFromPrimitive ;
8+ use core:: convert:: { TryFrom , TryInto } ;
9+ use num_enum :: TryFromPrimitive ;
1010
1111#[ derive( Clone , Copy , Debug , TryFromPrimitive ) ]
1212#[ repr( u8 ) ]
@@ -104,13 +104,7 @@ impl EmulatedDevice for VgaController {
104104 match port {
105105 Self :: VGA_INDEX => match val {
106106 PortWriteRequest :: OneByte ( b) => {
107- self . index =
108- VgaRegister :: try_from ( b[ 0 ] ) . ok_or_else ( || {
109- Error :: InvalidValue ( format ! (
110- "Invalid vga register 0x{:x}" ,
111- b[ 0 ]
112- ) )
113- } ) ?
107+ self . index = VgaRegister :: try_from ( b[ 0 ] ) ?;
114108 }
115109
116110 // The VGA controller allows a register update and data write
@@ -119,13 +113,7 @@ impl EmulatedDevice for VgaController {
119113 PortWriteRequest :: TwoBytes ( bytes) => {
120114 let index = bytes[ 1 ] ;
121115 let data = bytes[ 0 ] ;
122- self . index =
123- VgaRegister :: try_from ( index) . ok_or_else ( || {
124- Error :: InvalidValue ( format ! (
125- "Invalid vga register 0x{:x}" ,
126- index
127- ) )
128- } ) ?;
116+ self . index = VgaRegister :: try_from ( index) ?;
129117 self . registers [ self . index as usize ] = data;
130118 }
131119 _ => {
0 commit comments