gimli-rs / object

A unified interface for reading and writing object file formats
https://docs.rs/object/
Apache License 2.0
673 stars 156 forks source link

no_std support for ReadCache #652

Closed samcday closed 8 months ago

samcday commented 8 months ago

Hello! I'm using this wonderful crate in a no_std environment. In my particular case, I'm parsing UKI (PEs) files on an ESP (vfat) partition using the fatfs crate.

fatfs mainline branch works in no_std by simply defining their own variants of std::io::Read/Seek traits: https://github.com/rafalh/rust-fatfs/blob/master/src/io.rs ... It's worth noting that the current latest published release depends on the now-defunct core_io crate.

As it happens, I was able to get this working satisfactorily by simply duplicating the entirety of ReadCache + ReadCacheRange, and updating the Read+Seek trait references from std::io to fatfs. The trait signatures are otherwise identical, so everything "just worked" without me needing to wrap my head around how I might implement such a thing myself.

Which got me to thinking ... could the object crate do something similar? That is, export object::io::Read + object::io::Seek traits with some ergonomics to easily coerce std::io variants (not sure how to do that off the top of my head, my Rust-fu is weak).

samcday commented 8 months ago

Oh it's also worth noting that in no_std environment I had to explicitly bring in the memchr crate, since core::slice::memchr is unstable. I suppose object could also do that when std feature is absent.

philipc commented 8 months ago

Does #653 meet your needs?

I suppose object could also do that when std feature is absent.

It already does. However, it also needs the hashbrown crate, and I don't want that as a dependency all the time, so I added to no_std feature to enable this.

samcday commented 8 months ago

This is wonderful. I've just tested with your branch and confirm it works exactly as I'd hoped. Thank you!