duplicate icon indicating copy to clipboard operation
duplicate copied to clipboard

Substitution in strings

Open Emoun opened this issue 2 years ago • 0 comments

Short Description:

Enable substitution within string literals.

Motivation:

Substitution within the contents of string literals fits well with the overall functionality of duplicate. E.g. it could be used to change the wording on some strings depending on the duplicate.

Additionally, it enables the substitution of documentation comments. Currently, to do so can only be done using the doc attribute and substituting the whole string. Not being able to substitute in docs means our examples of generating different versions of functions for e.g. mutability or async don't work well if you need the documentation to be changed too. See #54. Enabling substitution within strings should (hopefully, needs more investigation) enable substitution within /// comments directly.

Lastly, it's not immediately intuitive that substitution wouldn't work within string literals, making it a pain point for users.

Design

During substition, if a string literal is encountered, run the substitutions within it too. To parse the contents of strings, the litrs crate can be used. See also this stackoverflow answer.

Misc:

Open questions:

  • [ ] Parsing the contents of string is not straight-forward as its would be given as &str and not TokenStream (if using littrs), meaning the normal method of identifying substitution identifiers wouldn't work. This is especially difficult with parametric substitution.
  • [ ] Should this be behind a feature flag or treated as a first-class feature?
  • [ ] Could this lead to confusion, where users wouldn't have expected substitution within strings?

Emoun avatar Apr 12 '23 19:04 Emoun