Skip to content

Conversation

@qrayven
Copy link
Contributor

@qrayven qrayven commented Sep 5, 2025

Description of change

⚠️ The PR is still a draft and subject to change:

  • removes the dependency on anyhow and replaces it with a generic Error

  • introduces the no_std flag, which removes the dependency on the std library

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How the change has been tested

⚠️ not tested yet

Change checklist

  • I have followed the contribution guidelines for this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that new and existing unit tests pass locally with my changes
  • I have updated the CHANGELOG.md, if my changes are significant enough

Copy link

@ft-filancore ft-filancore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As suggested in #5, a few preliminary comments regarding the no_std setup. If you have any questions, I'm happy to help.

default = ["std", "send-sync-storage"]
std = ["thiserror/std", "async-trait"]
send-sync-storage = []
no-std = ["thiserror", "async-trait"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a side note: cargo feature flags should be additive. Usually, you don't need a no_std feature flag if your modes of operations include no_std and std. You always include thiserror and async-trait as non-optional dependencies because you need them for no_std anyway. And then you only need the std feature flag which additionally activates their respective std flags.

In this specific case, the reason is more semantically rather than technical because currently enabling both std and no_std wouldn't conflict. Later, they might diverge and break the promise. As you don't cfg(feature = "no_std") anything, it should be fine to remove this.

Comment on lines +12 to +16
#[cfg(feature = "std")]
use std::error::Error as StdError;

#[cfg(not(feature = "std"))]
use core::error::Error as CoreError;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[cfg(feature = "std")]
use std::error::Error as StdError;
#[cfg(not(feature = "std"))]
use core::error::Error as CoreError;
use core::error::Error as CoreError;

std::error::Error is a reexport of core::error::Error so you don't need to differentiate between them, you can simplify this to always using the core version. Similarly, you can always use alloc::string::String and alloc::boxed::Box and it will be the same types as the std versions if the std library is available.

So in the end, your own Error enum does not even need feature-gated duplication.

#[cfg(feature = "std")]
extern crate std;

#[cfg(not(feature = "std"))]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest you remove this gate and simply always use the alloc types. You could even enable #![forbid(clippy::std_instead_of_alloc, clippy::std_instead_of_core)] to force yourself into using the alloc and the core types over the std types where available.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cargo toml lacks the MSRV bump to 1.81 to use core::error::Error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants