js equivalent of str.replace(.., replacerFunction()) in rust

I am currently try to learn rust by transpiling some scripts from js to wasm.

In js there is this function:

string.prototype.replace(substr, replacerFunction())

I am searching a rust function for this case. I know there is also a string.replace func, but I think I cant pass there a custom replacerFunction to it.

I have this snippet in js:

const sentence = 'This is a sentence';
modifiedSentence = sentence.replace(/p{L}+/gu, (word) => {

      // imaging some heavily transformation on `word` here, based on its type like (verb, object or subject).

      return word;
});

Maybe a regex only solution would somehow be possible, but not for me 🙂

Thanks for any hints !