rust-vfs icon indicating copy to clipboard operation
rust-vfs copied to clipboard

no_std compatiblity

Open robamu opened this issue 3 years ago • 6 comments

Hi!

I am looking for a generic file system abstraction which can possible be re-used with something like https://github.com/littlefs-project/littlefs / https://docs.rs/littlefs/latest/littlefs/ . My goal was to write components which depend on a generic file system abstraction which can be used on larger system like embedded Linux, but also on microcontroller which might not have a full run-time and use a custom or vendor-supplied filesystem.

Do you have any plans to add no_std support for your crate in the future? From what I have seen from the generic FS trait https://docs.rs/vfs/latest/vfs/filesystem/trait.FileSystem.html , alloc support is defnitely required, but there is also a dependency on std::io traits like Read and Write. These trait might move into core soon: https://github.com/rust-lang/rust/issues/48331 , but those traits not being in core is what probably makes this feature non-trivial right now..

Kind Regards Robin

robamu avatar Nov 10 '22 08:11 robamu

Hi there, interesting use case! Missing Read and Write support in core would probably make the API quite awkward as of now.

But I'll look forward to exploring that possibility once these traits have landed in core. Alloc might be an issue, but maybe there is some creative solution to that as well.

manuel-woelker avatar Nov 12 '22 06:11 manuel-woelker

I don't think Read and Write will be available in core anytime soon. For the time being, the acid_io crate might be a good alternative.

A first step could be compatibility with #[no_std] + alloc, which is a very common setup as well.

robertbastian avatar Jan 26 '23 15:01 robertbastian

#[no_std] and alloc already sounds very good! I would say that most bare metal system where a file system is available in some shape or form also have sufficient heap for alloc support.

robamu avatar Aug 04 '23 07:08 robamu

embedded_io provides Read and Write traits. And if the std feature is enabled, they automatically implement stdlib Read and Write traits. The crate is widely used in embedded systems.

orsinium avatar May 28 '24 11:05 orsinium

Those traits are very useful, and I suppose it could be an option to add new trait similar to https://docs.rs/vfs/latest/vfs/filesystem/trait.FileSystem.html which uses the embedded_io traits instead..

robamu avatar May 28 '24 14:05 robamu

Hmm, I am wondering what the best approach is here. It might make sense to have rust-vfs define its own Read and Write traits, and have those blanket implement their counterparts in std or embedded_io if those dependencies/features are enabled. This would decouple this crate from any dependencies, and be generic over possible dependencies.

Would that approach work for your use case?

manuel-woelker avatar Jun 09 '24 05:06 manuel-woelker

According to crates.io statistics, embedded-io is more used than core-io and acid-io. I could personally choose embedded-io.

Also, it is maintained by an official team of Rust.

Conaclos avatar Aug 20 '25 15:08 Conaclos