Rust Syntax for implicit closure parameter

Can anyone point me to the Syntax in Rust for implicit closure parameter? I know I have seen it in the forum before, but can't find it :laughing:.

In Scala, it's used like this: and

You can ignore a closure parameter, and, it being a closure, you can close over free variables from the closure's lexical environment.
But there is no such thing as an implicit parameter in Rust.

But given the code samples, it seems to me you just want to map over a collection. The Rust equivalents would be roughly:

let ids: <TYPE> = some_seq.iter().map(|x|;
let values: <TYPE> = some_seq.iter().map(MyWrapperType).collect();

A couple of notes:

  1. when using such constructs you have to specify what the output type should be, eg Vec<Id>
  2. In the second iterator chain there is an assumption that MyWrapperType is a newtype, approximately defined as struct MyWrapperType(pub X); if some_seq is a collection of elements of type X.

Rust can usually infer the type within the collection in this pattern.

let v: Vec<_> = other.iter().map(f).collect();

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.