Skip to content
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

What is the scope of no_std support? #467

Open
yanshay opened this issue Nov 19, 2024 · 5 comments
Open

What is the scope of no_std support? #467

yanshay opened this issue Nov 19, 2024 · 5 comments
Labels
enhancement New feature or request found in the field A user of SNAFU found this when trying to use it

Comments

@yanshay
Copy link

yanshay commented Nov 19, 2024

I'm trying to use Snafu in a no_std environment, and the basic example from the docs doesn't work.

It can't find Whatever and I checked the sourced and it's behind std feature.

So what is the scope of support for no_std?

@alerque
Copy link

alerque commented Nov 19, 2024

As far as I understand it whatever itself does not support no_std, so this doesn't seem unexpected.

@yanshay
Copy link
Author

yanshay commented Nov 19, 2024

As far as I understand it whatever itself does not support no_std, so this doesn't seem unexpected.

Oh, any technical reason for that?
If I understand correctly whatever is the equivalent to anyhow crate and I recall I used it in the past in no_std.

@shepmaster
Copy link
Owner

Yes, snafu::Whatever requires the standard library for allocation (via Box and String) as well as the Backtrace type which should usually be provided by the standard library on modern Rust versions.

From anyhow's README (emphasis mine):

To depend on Anyhow in no_std mode, disable our default enabled “std” feature in Cargo.toml. A global allocator is required.

So anyhow works with libcore + liballoc. I'd expect that SNAFU could do the same 1 and just no one has needed that specific distinction yet. Do you have liballoc available?

Footnotes

  1. Or close to the same; you could always define your own Whatever at least.

@shepmaster shepmaster added enhancement New feature or request found in the field A user of SNAFU found this when trying to use it labels Nov 19, 2024
@yanshay
Copy link
Author

yanshay commented Nov 19, 2024

So anyhow works with libcore + liballoc. I'd expect that SNAFU could do the same 1 and just no one has needed that specific distinction yet. Do you have liballoc available?

I have alloc. In embedded there is a distinction between std and alloc since alloc is quite common to have.

@shepmaster
Copy link
Owner

shepmaster commented Nov 19, 2024

there is a distinction between std and alloc

I'm aware 😄. It's just that most of my embedded usage / knowledge of usage has been places with no allocation capability (e.g. tiny devices, Windows kernel drivers). In addition, I don't like using Whatever because I don't want to allocate if I can ever help it, plus I like having a known set of errors.

Anyway, can you try this branch and see if it works for your case?

https://github.com/shepmaster/snafu/tree/alloc

That should look something like this in your Cargo.toml:

[dependencies.snafu]
default-features = false
features = ["rust_1_81", "alloc"]
git = "https://github.com/shepmaster/snafu"
branch = "alloc"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request found in the field A user of SNAFU found this when trying to use it
Projects
None yet
Development

No branches or pull requests

3 participants