@@ -76,12 +76,12 @@ impl Expression {
76
76
return Err ( DscError :: Parser ( "Expression index not supported" . to_string ( ) ) ) ;
77
77
} ,
78
78
_ => {
79
- return Err ( DscError :: Parser ( format ! ( "Invalid accessor kind: '{:? }'" , accessor_kind ) ) ) ;
79
+ return Err ( DscError :: Parser ( format ! ( "Invalid accessor kind: '{accessor_kind }'" ) ) ) ;
80
80
} ,
81
81
}
82
82
} ,
83
83
_ => {
84
- return Err ( DscError :: Parser ( format ! ( "Invalid accessor kind: '{:? }'" , accessor_kind ) ) ) ;
84
+ return Err ( DscError :: Parser ( format ! ( "Invalid accessor kind: '{accessor_kind }'" ) ) ) ;
85
85
} ,
86
86
} ;
87
87
accessors. push ( value) ;
@@ -111,7 +111,7 @@ impl Expression {
111
111
pub fn invoke ( & self , function_dispatcher : & FunctionDispatcher , context : & Context ) -> Result < Value , DscError > {
112
112
let result = self . function . invoke ( function_dispatcher, context) ?;
113
113
trace ! ( "Function result: '{:?}'" , result) ;
114
- if self . accessors . len ( ) > 0 {
114
+ if self . accessors . is_empty ( ) {
115
115
debug ! ( "Evaluating accessors" ) ;
116
116
let mut value = result;
117
117
for accessor in & self . accessors {
@@ -122,7 +122,7 @@ impl Expression {
122
122
}
123
123
if let Some ( object) = value. as_object ( ) {
124
124
if !object. contains_key ( member) {
125
- return Err ( DscError :: Parser ( format ! ( "Member '{:? }' not found" , member ) ) ) ;
125
+ return Err ( DscError :: Parser ( format ! ( "Member '{member }' not found" ) ) ) ;
126
126
}
127
127
value = object[ member] . clone ( ) ;
128
128
}
@@ -135,7 +135,10 @@ impl Expression {
135
135
if !index. is_number ( ) {
136
136
return Err ( DscError :: Parser ( "Index is not a number" . to_string ( ) ) ) ;
137
137
}
138
- let index = index. as_u64 ( ) . unwrap ( ) as usize ;
138
+ let Some ( index) = index. as_u64 ( ) else {
139
+ return Err ( DscError :: Parser ( "Index is not a number" . to_string ( ) ) ) ;
140
+ } ;
141
+ let index = usize:: try_from ( index) ?;
139
142
if index >= array. len ( ) {
140
143
return Err ( DscError :: Parser ( "Index out of bounds" . to_string ( ) ) ) ;
141
144
}
0 commit comments