Skip to content

Commit 15ddbf8

Browse files
committed
fix clippty
1 parent affa724 commit 15ddbf8

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

dsc_lib/src/parser/expressions.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ impl Expression {
7676
return Err(DscError::Parser("Expression index not supported".to_string()));
7777
},
7878
_ => {
79-
return Err(DscError::Parser(format!("Invalid accessor kind: '{:?}'", accessor_kind)));
79+
return Err(DscError::Parser(format!("Invalid accessor kind: '{accessor_kind}'")));
8080
},
8181
}
8282
},
8383
_ => {
84-
return Err(DscError::Parser(format!("Invalid accessor kind: '{:?}'", accessor_kind)));
84+
return Err(DscError::Parser(format!("Invalid accessor kind: '{accessor_kind}'")));
8585
},
8686
};
8787
accessors.push(value);
@@ -111,7 +111,7 @@ impl Expression {
111111
pub fn invoke(&self, function_dispatcher: &FunctionDispatcher, context: &Context) -> Result<Value, DscError> {
112112
let result = self.function.invoke(function_dispatcher, context)?;
113113
trace!("Function result: '{:?}'", result);
114-
if self.accessors.len() > 0 {
114+
if self.accessors.is_empty() {
115115
debug!("Evaluating accessors");
116116
let mut value = result;
117117
for accessor in &self.accessors {
@@ -122,7 +122,7 @@ impl Expression {
122122
}
123123
if let Some(object) = value.as_object() {
124124
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")));
126126
}
127127
value = object[member].clone();
128128
}
@@ -135,7 +135,10 @@ impl Expression {
135135
if !index.is_number() {
136136
return Err(DscError::Parser("Index is not a number".to_string()));
137137
}
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)?;
139142
if index >= array.len() {
140143
return Err(DscError::Parser("Index out of bounds".to_string()));
141144
}

0 commit comments

Comments
 (0)