Skip to content

Owned variants of APIs where &str is used #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
abnormalmaps opened this issue Apr 19, 2025 · 0 comments
Open

Owned variants of APIs where &str is used #200

abnormalmaps opened this issue Apr 19, 2025 · 0 comments

Comments

@abnormalmaps
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant