QEDK / configparser-rs

A simple configuration parsing utility with no dependencies built on Rust.
https://crates.io/crates/configparser
Other
66 stars 21 forks source link

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

Open WhyNotHugo opened 1 year ago

WhyNotHugo commented 1 year ago

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.

QEDK commented 1 year ago

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.