diff --git a/quest/m3/README.md b/quest/m3/README.md index fa33b7f98..0abf6f95e 100644 --- a/quest/m3/README.md +++ b/quest/m3/README.md @@ -53,3 +53,4 @@ generic std gap is planned here even when moq never calls it. - [A box's clone_from, and a vector's AsRef and AsMut](/quest/m3/ts-box-vec-conversions.md) - `clone_from` of a `Box` and `AsRef<[T]>` of a `Vec` translate - [A std map with a crate's own BuildHasher](/quest/m3/ts-map-own-hasher.md) - std's and hashbrown's maps built with a crate's own hasher translate for keys that are JS objects - [A crate's own hasher that JS copies](/quest/m3/ts-copied-hasher.md) - an enum `Hasher`, whose `&mut` is a place, hashes as a struct one does +- [A reference to a closure as a string pattern](/quest/m3/ts-closure-patterns.md) - `s.contains(&f)` and `s.split(&mut f)` translate, leaving the closure to its owner to drop diff --git a/quest/m3/ts-closure-patterns.md b/quest/m3/ts-closure-patterns.md new file mode 100644 index 000000000..c42cb2515 --- /dev/null +++ b/quest/m3/ts-closure-patterns.md @@ -0,0 +1,24 @@ +# [S] A reference to a closure as a string pattern + +## Goal + +[rust2-ts](/ts/README.md) translates a `str` search given a reference to a closure as its +pattern, `s.contains(&f)` or `s.split(&mut f)`. The search calls the closure as std's does +and never drops it, which leaves the drop to its owner. Differential tests against native +Rust prove it, covering closures that own a value that drops and searches that return a +value and an iterator. + +## Plan + +Found in [#471](https://github.com/moq-dev/rust2/pull/471), which made a search drop a +closure it owns. A reference to one is refused as a pattern other than a `char`, a +`&str`, a predicate, or chars, as the README's list of what is refused says. std takes +`&F` for an `F: Fn` and `&mut F` for an `F: FnMut`, as each implements `FnMut`. + +The closure drop logic that #471 extended already tells a lent closure from an owned one, +and wraps a lent one in `rt.lent` for an iterator that would drop what it holds. A +`&mut` to a function JS copies is that function's place. Watch that a lent closure is +neither dropped by the search nor by the iterator it returns, and drop the refusal from the +README once it translates. + +Public API: the translator's output.