Skip to content

Commit

Permalink
Use Option::is_none_or
Browse files Browse the repository at this point in the history
  • Loading branch information
jplatte committed Dec 28, 2024
1 parent 614f587 commit 2389870
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,7 @@ fn fmt_value(value: &mut Value, config: &Config) {
// get here from a headed table (`[header] key = val`)
val => {
if config.space_around_eq
&& val
.decor()
.prefix()
.map_or(true, |s| s.as_str().map_or(true, str::is_empty))
&& val.decor().prefix().and_then(|r| r.as_str()).is_none_or(str::is_empty)
{
val.decor_mut().set_prefix(" ");
}
Expand Down Expand Up @@ -240,7 +237,7 @@ fn fmt_table(table: &mut Table, config: &Config) {
let keys: Vec<_> = table.iter().map(|(k, _)| k.to_owned()).collect();
for key in keys {
let is_value_for_space = table.get(&key).is_some_and(|item| {
item.is_value() && item.as_inline_table().map_or(true, |t| !t.is_dotted())
item.is_value() && item.as_inline_table().is_none_or(|t| !t.is_dotted())
});

let mut dec = table.key_mut(&key).unwrap();
Expand Down Expand Up @@ -268,7 +265,7 @@ fn fmt_table(table: &mut Table, config: &Config) {
// This is weirdly broken, inserts underscores into `[foo.bar]` table
// headers. Revisit later.
if config.space_around_eq
&& dec.suffix().and_then(RawString::as_str).map_or(true, str::is_empty)
&& dec.suffix().and_then(RawString::as_str).is_none_or(str::is_empty)
&& is_value_for_space
{
dec.set_suffix(format!(
Expand Down

0 comments on commit 2389870

Please sign in to comment.