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

By-ref access to changed value #51

Closed
Zoybean opened this issue Oct 6, 2023 · 2 comments
Closed

By-ref access to changed value #51

Zoybean opened this issue Oct 6, 2023 · 2 comments

Comments

@Zoybean
Copy link

Zoybean commented Oct 6, 2023

similar::Change allows owned access to the contained value by cloning it, in the value method. Could it also provide by-reference access?

impl Change<T> {
    pub fn value_ref(&self) -> &T {
        &self.value
    }
}

This might lead to issues if T has interior mutability, but I figure if someone is diffing something with interior mutability, this is the least of your worries.

@mitsuhiko
Copy link
Owner

What type of T do you have?

@Zoybean
Copy link
Author

Zoybean commented Oct 7, 2023

It's not something I can share directly, but it represents a record in a time-series.
The reason I want this is not so much because I can't clone the data, but because the things I'm doing to it are easier if I operate only on references, not owned data (maybe solvable if we had lending iterators, but that's probably beside the point)

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

2 participants