configparser-rs icon indicating copy to clipboard operation
configparser-rs copied to clipboard

`load` or `read` without creating a clone?

Open WhyNotHugo opened this issue 2 years ago • 1 comments

Whenever data is read via load or read, the data Ini instance is mutated in place, but a clone of the inner data is returned too. So I end up with two copies of the data.

Why return a clone of the data? HashMap's Clone implementation is recursive, so this ends up copying the entire structure. Am I missing something here?

Is it somehow possible to do something like Init::read, but only get one copy of the data in memory? I don't need two copies. I know that I can just drop the clone, but I don't see the point it copying data just to drop it.

WhyNotHugo avatar Jun 23 '23 14:06 WhyNotHugo

Whenever data is read via load or read, the data Ini instance is mutated in place, but a clone of the inner data is returned too. So I end up with two copies of the data.

Why return a clone of the data? HashMap's Clone implementation is recursive, so this ends up copying the entire structure. Am I missing something here?

Is it somehow possible to do something like Init::read, but only get one copy of the data in memory? I don't need two copies. I know that I can just drop the clone, but I don't see the point it copying data just to drop it.

This is intentional (to some extent), basically some implementations are intended to mutate in-place and others are meant to return, so it provides the best of both worlds at the cost of using more memory. If you wanted, you could simply not assign it and the compiler would know to discard the return value. In all cases, the internal impl will need to store a hashmap. In the future however, it might be beneficial to do load_inplace() / read_inplace()-esque functions.

QEDK avatar Jun 23 '23 15:06 QEDK