Skip to content
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

qualify lifetime on Utf8ResultRef::as_bytes result #335

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

froydnj
Copy link

@froydnj froydnj commented Sep 7, 2023

Without this, you can't write something like:

fn read_slice_ref<'a, R: value_ref::BorrowRead<'a>>(r: &mut R) -> Option<&'a [u8]> {
    match value_ref::read_value_ref(r).ok()? {
        rmpv::ValueRef::Binary(v) => Some(v),
        rmpv::ValueRef::String(u) => Some(u.as_bytes()),
        _ => None,
    }
}

because the compiler (version 1.72) complains:

error[E0515]: cannot return value referencing local variable `u`
   --> src/main.rs:124:38
    |
124 |         rmpv::ValueRef::String(u) => Some(u.as_bytes()),
    |                                      ^^^^^------------^
    |                                      |    |
    |                                      |    `u` is borrowed here
    |                                      returns a value referencing data owned by the current function

With this PR, things work as one would expect.

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

Successfully merging this pull request may close these issues.

1 participant