Skip to content

What's the idiomatic approach for Replacers that may fail? #648

Closed
@Zireael-N

Description

@Zireael-N

I've been trying to reimplement the following logic in Rust: Lua, PHP.

Basically, they use a regular expression to unescape some sequences and throw an exception if it's not a known one. I tried to do a similar thing but ran into an issue that Replacer is expected to be a function that returns String, not Result<String, _>.

I circumvented this by panic!()-ing inside my Replacer and wrapping a replace_all() call in std::panic::catch_unwind() but, AFAIK, it's a pretty terrible solution.

Is there a better approach? (Other than not using regular expressions for deserializing, haha)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions