Skip to content

Support no_std #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
glandium opened this issue Mar 19, 2018 · 2 comments · Fixed by #31
Closed

Support no_std #18

glandium opened this issue Mar 19, 2018 · 2 comments · Fixed by #31

Comments

@glandium
Copy link

There are multiple use cases for no_std, most of which have no use for errno. But a few use cases involving low-level code that can't use libstd can still use e.g. libc. No libstd means no std::io, which means no errno from there.

Those use cases could be considered niches, and I would totally understand that a small crate for a couple uses in the entire rust ecosystem might not be worth. Being at the beginning of my project, I only need read access to errno, and have copy/pasted the relevant parts for that for now (and only the unix parts for prototyping purposes), but I will eventually need cross-platform and write access as well. To give you an idea how niche my own use case is: I'm reimplementing a malloc() library (namely, mozjemalloc, the allocator in use in Firefox) in rust.

@lambda-fairy
Copy link
Owner

Thanks for the write-up!

I think the hardest part will be writing the Display instance, since that would require decoding the error message provided by the OS.

On POSIX, we can use core::str::from_utf8. Need to be careful with decoding errors, though. The current implementation replaces errors with U+FFFD; to replicate this in the non-allocating implementation, we will need to call str::from_utf8 in a loop.

As for Windows: there is a non-allocating UTF-16 decoder in the standard library, but it's in the unstable std_unicode crate instead of core. I have filed an issue (rust-lang/rust#49319) to fix this.

There is also the question of whether it's efficient to write the message one character at a time, which is what a naïve implementation using char::decode_utf16 would do. I suspect that it doesn't matter in practice, but the implementer will need to confirm this.

@glandium
Copy link
Author

At least for my niche case, I don't care about Display at all. In fact, I wouldn't have a use for it. I'm not entirely sure it's worth worrying about Display until someone that needs the errno crate with no_std actually needs it. Who knows, I might even end up being the only user of this crate with no_std.

sunfishcode added a commit to sunfishcode/rust-errno that referenced this issue Oct 23, 2021
Add a "std" feature which is enabled by default, and enable `no_std`
when it is not enabled. Disable all `Display` and `Debug` features
in `no_std` mode.

My specific use case for this is [rsix](https://crates.io/crates/rsix),
which has a no_std branch, and which uses the `errno` crate in its
`libc`-using backend.

Fixes lambda-fairy#18.
lambda-fairy pushed a commit that referenced this issue Oct 25, 2021
Add a "std" feature which is enabled by default, and enable `no_std`
when it is not enabled. Disable all `Display` and `Debug` features
in `no_std` mode.

My specific use case for this is [rsix](https://crates.io/crates/rsix),
which has a no_std branch, and which uses the `errno` crate in its
`libc`-using backend.

Fixes #18.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants