mitsuhiko / similar

A high level diffing library for rust based on diffs
https://insta.rs/similar
Apache License 2.0
949 stars 31 forks source link

By-ref access to changed value #51

Closed Zoybean closed 11 months ago

Zoybean commented 11 months ago

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 commented 11 months ago

What type of T do you have?

Zoybean commented 11 months ago

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)