Seeking method name convention

Hi there Rustaceans,

I‘m currently struggling with a good method naming convention. The use case:
I have a method on an struct then requires a closure to be passed where the closure gets called with either a ref or a mutable ref to inner data of the structure.

Like

impl Foo {
  fn use<F>(&self, f: F)
    where F: FnOnce(&InnerFoo) {
  }
}

What would be good choices for the function use and the mutabler counterpart use_mut ? I couldn‘t find any guidelines or proposals on this.

So any proposal or hint would be appreciated :slight_smile:

The thing it most reminds me of in existing usage is the with fn you get from a thread_local! as documented in LocalKey. modulo lifetime and return value the type signature is passingly similar at least.

2 Likes

with and with_mut
or
with_ref and with_mut

are definitely the most idiomatic in Rust for this pattern.

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.