annotate-snippets-rs icon indicating copy to clipboard operation
annotate-snippets-rs copied to clipboard

Owned variants of APIs where &str is used

Open abnormalmaps opened this issue 6 months ago • 0 comments

I've been using this crate for personal project of mine, and I've sometimes found myself wanting to do something like this this:

fn make_message(token: &Token) -> Message<'_> {
    Level::Error.header(format!("unhandled token `{}`", token.src))
        .[...]
}

For obvious reasons, this doesn't directly work. To make it work the error string has to be stored out of line elsewhere, but this isn't always convenient (at least, it isn't for my design). It would be easier if there was a variant of (at least some) of the APIs which accepts a String instead, and the fields internally store a Cow<'src, 'str> instead of a &'src str.

Incidentally, this also might help people who have use cases that would have wanted #101, since it would be easier to directly format into a String that is stored by the Message.

abnormalmaps avatar Apr 19 '25 21:04 abnormalmaps