I have a situation where I have a 10mb String that I need to prepend 50-500bytes to the beginning 100 times, with the first 50-500 bytes different each time. This would be massively wasteful to reallocate 100 times. I was hoping there could be a way to make multiple &str appear combined as a String to a function I need to pass it to for generating a hash of the text.
One way I could do this is allocate the data once, and then just exchange the beginning data each time but this seems tricky to get everything aligned correctly. It would also force my code to be synchronous since a mutable reference cannot be shared between threads.
You can't make something that's not a String look like a String, because String is a type, not a trait.
Is the hash function under your control? If so, could you modify it to take a Read rather than a String? That would be a better API regardless (IMO), and then you could quite easily implement Read for a chain of &str
I need to take a SHA256 sum of the data with a package like: sha256 - Rust
I have not gotten to the point where I am doing the sum yet so I haven't actually researched the packages, I'm just trying to think ahead. What you proposed is interesting, I hadn't thought of that. I'm not sure if that sha256 package supports that but it surely might, perhaps you could tell me.