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

Derive Clone for kv::Value? #667

Closed
SpriteOvO opened this issue Feb 13, 2025 · 0 comments · Fixed by #668
Closed

Derive Clone for kv::Value? #667

SpriteOvO opened this issue Feb 13, 2025 · 0 comments · Fixed by #668

Comments

@SpriteOvO
Copy link
Contributor

SpriteOvO commented Feb 13, 2025

Currently the only way to clone a kv::Value seems to be ToValue::to_value(), it limits the downstream kv::Value wrappers to implement Clone.

For example:

// #[derive(Clone)]
struct Wrapper<'a>(log::kv::Value<'a>);

impl Clone for Wrapper<'_> {
    fn clone(&self) -> Self {
        Self(self.0.to_value())
    }
}

First, the wrapper can't directly #[derive(Clone)] as kv::Value does not implement Clone.

Second, the to_value() call raises a lifetime error:

lifetime may not live long enough
method was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`

I think adding a #[derive(Clone)] to kv::Value should be fine and it solves the problem.

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 a pull request may close this issue.

1 participant