Skip to content

Commit 4f00c7f

Browse files
committed
ast-builder: Add method_chain_expr convenience function
1 parent f84b233 commit 4f00c7f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

c2rust-ast-builder/src/builder.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,17 @@ impl Builder {
664664
)))
665665
}
666666

667+
/// A convenience function for calling multiple methods in a chain.
668+
pub fn method_chain_expr(
669+
self,
670+
expr: Box<Expr>,
671+
calls: Vec<(PathSegment, Vec<Box<Expr>>)>,
672+
) -> Box<Expr> {
673+
calls.into_iter().fold(expr, |expr, (seg, args)| {
674+
mk().method_call_expr(expr, seg, args)
675+
})
676+
}
677+
667678
pub fn tuple_expr(self, exprs: Vec<Box<Expr>>) -> Box<Expr> {
668679
Box::new(Expr::Tuple(ExprTuple {
669680
attrs: self.attrs,

0 commit comments

Comments
 (0)