Skip to content

Closure-level inline constants #3687

Description

@sojuz151

I propose to add closure-level inline constants. For example the following code

let closeure_uuid = Uuid::new_v4();
let lambda = ||  {
println!("Execution UUID {}",Uuid::new_v4());
println!("Closure UUID {}",closeure_uuid);
};
lambda ();
lambda ();

It could be rewritten as

let lambda = ||  {
println!("Execution UUID {}",Uuid::new_v4());
println!("Closure UUID {}",cc{Uuid::new_v4())});
};
lambda ();
lambda ();

with a new cc keyword similar to constant. This would have similar advantages as inline_const rust-lang/rust#104087. Use cases:

Finer control on what is getting moved inside the lambda. For example

cc{very_larnge_vector.iter().min()}

or

cc{struct.field.other_filed}

More ergonomic dealing with ref counting. Example:

cc{button.clone()}.enable();

Those expressions should be executed when the closure is created and dropped when the closure is dropped.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions