Thanks for the information.
It seems that the wrapper of the library handle that already in some way so.... I let the library handle that.
I now have a fully functional version (with envsys data), even if I am not sure about the energy_rate for now, I think it is hard to try two programs at the exact same time and ensure the very same value.
(But in my test they were very close, to the dot precision in terms of difference).
(I took inspiration on the existing Freebsd as well as golang version distatus for energy_rate units/management (I think the latter have a memory leak, because the mmap allocated by the kernel which is not handled by golang gc AFAIK is not munmaped))
If you want you can test on your computer with the example.
I only have one laptop with NetBSD and only tested with acpibat.
I am also interested in feedback on systems without any battery (Desktop or VM) if anyone is interested in just installing rust and some dependencies needed (probably cmake, pkgconfig, git (libgit), because of some rust dependencies), cloning, switching to netbsd branch and cargo run --example oneshot
and/or cargo run --example all
You migh need the following .cargo/config.toml : to link with pkgsrc libraries
[target.x86_64-unknown-netbsd]
rustflags = ["-C", "link-args=-Wl,-R/usr/pkg/lib,-R/usr/X11R7/lib"]
Or the equivalent on arm (I am also curious about aarch64 systems with acpi batteries)
Repo URL (again) https://github.com/naguam/rust-battery/tree/netbsd
Please ensure you are testing the branch netbsd if you are testing.
I still need to clean up the repo (rebase, squash) and maybe some minor fixes before making my pull request.
I learned a lot along this side project (for me) on best practices in Rust and reading some NetBSD code and understanding differences with other systems, in terms of battery management.
Thanks a lot the help here as well.