gimli-rs / gimli

A library for reading and writing the DWARF debugging format
https://docs.rs/gimli/
Apache License 2.0
853 stars 108 forks source link

Reader::to_{slice,string} -> s/Cow/&// #655

Closed tamird closed 1 year ago

tamird commented 1 year ago

The implementations of these methods always return references; formalize this in the API. The implementations of Reader::to_slice are all infallible; formalize this as well.

bjorn3 commented 1 year ago

A custom reader which reads fragments of a file on the fly would have to return Cow::Owned, right?

tamird commented 1 year ago

I don't see why; can you help me understand?

What you're describing sounds mutable, but these methods take &self.

philipc commented 1 year ago

@bjorn3 is correct. Using Cow was an intentional design decision to allow a Reader implementation like that. It would use interior mutability. As such, we won't be making this change.