removed unwraps (#430)

This commit is contained in:
Fernando Herrera
2021-12-04 12:38:21 +00:00
committed by GitHub
parent eed22605ef
commit 8a06ea133b
24 changed files with 233 additions and 159 deletions

View File

@ -38,7 +38,7 @@ impl Command for Format {
match specified_pattern {
Err(e) => Err(e),
Ok(pattern) => {
let string_pattern = pattern.as_string().unwrap();
let string_pattern = pattern.as_string()?;
let ops = extract_formatting_operations(string_pattern);
format(input, &ops, call.head)
}
@ -184,9 +184,7 @@ fn format_record(
val: col_name.clone(),
span: Span::unknown(),
}]) {
Ok(value_at_column) => {
output.push_str(value_at_column.as_string().unwrap().as_str())
}
Ok(value_at_column) => output.push_str(value_at_column.as_string()?.as_str()),
Err(se) => return Err(se),
}
}

View File

@ -142,7 +142,7 @@ fn action(
span: head,
}
} else {
let c = character.as_ref().unwrap(); // we already know this flag needs to exist because the command is type checked before we call the action function
let c = character.as_ref().expect("we already know this flag needs to exist because the command is type checked before we call the action function");
let mut res = c.repeat(s - val.chars().count());
res += val;
Value::String {

View File

@ -143,7 +143,7 @@ fn action(
}
} else {
let mut res = val.to_string();
res += &character.as_ref().unwrap().repeat(s - val.chars().count());
res += &character.as_ref().expect("we already know this flag needs to exist because the command is type checked before we call the action function").repeat(s - val.chars().count());
Value::String {
val: res,
span: head,

View File

@ -143,7 +143,7 @@ where
input,
);
let to_trim = match options.character.as_ref() {
Some(v) => v.as_string().unwrap().chars().next(),
Some(v) => v.as_string()?.chars().next(),
None => None,
};