Skip to content

Commit

Permalink
chore: use Option::transpose() (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr authored May 1, 2024
1 parent d5963ce commit a9b2c9f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions crates/core/src/pattern_compiler/contains_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ impl NodeCompiler for ContainsCompiler {
let contains = PatternCompiler::from_node(&contains, context)?;
let until = node
.child_by_field_name("until")
.map(|n| PatternCompiler::from_node(&n, context));
let until = until.map_or(Ok(None), |v| v.map(Some))?;
.map(|n| PatternCompiler::from_node(&n, context))
.transpose()?;
Ok(Contains::new(contains, until))
}
}
4 changes: 2 additions & 2 deletions crates/core/src/pattern_compiler/if_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl NodeCompiler for IfCompiler {
let else_ = node
.child_by_field_name("else")
.map(|e| PatternCompiler::from_node(&e, context))
.map_or(Ok(None), |v| v.map(Some))?;
.transpose()?;
Ok(If::new(if_, then, else_))
}
}
Expand All @@ -54,7 +54,7 @@ impl NodeCompiler for PrIfCompiler {
let else_ = node
.child_by_field_name("else")
.map(|e| PredicateCompiler::from_node(&e, context))
.map_or(Ok(None), |v| v.map(Some))?;
.transpose()?;
Ok(PrIf::new(if_, then, else_))
}
}
4 changes: 2 additions & 2 deletions crates/core/src/pattern_compiler/log_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ impl NodeCompiler for LogCompiler {
.map(|n| {
let name = n.text()?;
let variable = VariableCompiler::from_node(&n, context)?;
Ok(VariableInfo::new(name.to_string(), variable))
Ok::<_, anyhow::Error>(VariableInfo::new(name.to_string(), variable))
})
.map_or(Ok(None), |v: Result<VariableInfo>| v.map(Some))?;
.transpose()?;

Ok(Log::new(variable, message))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/pattern_compiler/range_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ impl NodeCompiler for RangeCompiler {
fn node_to_int(node: &NodeWithSource, field: &str) -> Result<Option<u32>> {
node.child_by_field_name(field)
.map(|n| Ok(n.text()?.parse::<u32>()?))
.map_or(Ok(None), |v| v.map(Some))
.transpose()
}

0 comments on commit a9b2c9f

Please sign in to comment.