simplify test_func
This commit is contained in:
parent
5563679cdf
commit
5e756b0a70
@ -179,17 +179,13 @@ pub fn test_func(function_string: &str) -> Option<String> {
|
||||
let var_names = parse_result.unwrap().var_names().to_vec();
|
||||
|
||||
if var_names != ["x"] {
|
||||
let var_names_not_x: Vec<String> = var_names
|
||||
let var_names_not_x: Vec<&String> = var_names
|
||||
.iter()
|
||||
.filter(|ele| *ele != "x")
|
||||
.cloned()
|
||||
.collect::<Vec<String>>();
|
||||
.filter(|ele| ele != &"x")
|
||||
.collect::<Vec<&String>>();
|
||||
|
||||
return match var_names_not_x.len() {
|
||||
1 => {
|
||||
let var_name = &var_names_not_x[0];
|
||||
Some(format!("Error: invalid variable: {}", var_name))
|
||||
}
|
||||
1 => Some(format!("Error: invalid variable: {}", var_names_not_x[0])),
|
||||
_ => Some(format!("Error: invalid variables: {:?}", var_names_not_x)),
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user