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

Unable to use validation in no-std crate #120

Closed
TheBestTvarynka opened this issue Jan 20, 2024 · 3 comments · Fixed by #122
Closed

Unable to use validation in no-std crate #120

TheBestTvarynka opened this issue Jan 20, 2024 · 3 comments · Fixed by #122

Comments

@TheBestTvarynka
Copy link

Hi,
I'm trying to write a small new type struct with a simple validation in the no-std crate. My current code looks like this:

#[nutype(
    validate(less = 13),
    derive(Debug, Clone, PartialEq, Eq)
)]
pub struct Month(u8);

But unfortunately, I got the following error:

error[E0433]: failed to resolve: could not find `std` in the list of imported crates
  --> src/lib.rs:7:1
   |
7  | / #[nutype(
8  | |     validate(less = 100),
9  | |     derive(Debug, Clone, PartialEq, Eq)
10 | | )]
   | |__^ could not find `std` in the list of imported crates
   |
   = help: consider importing one of these items:
           crate::__nutype_private_Year__::core::error
           core::error
   = note: this error originates in the attribute macro `nutype` (in Nightly builds, run with -Z macro-backtrace for more info)

Is it a bug or just expected behavior?

Thanks in advance

@greyblake
Copy link
Owner

@TheBestTvarynka Thanks for the report.

Generally I tried to use ::core as much as possible instead of ::std but I did not test it for real with no-std.
I think supporting no-std should be possible with a bit of work / tuning.

@greyblake
Copy link
Owner

greyblake commented Jan 28, 2024

@TheBestTvarynka I just published 0.4.1-beta.1, please give it a try.
Note:

  • String type is still not supported in no_std environment.
  • Use default-features = false for nutype dependency

@TheBestTvarynka
Copy link
Author

@greyblake yes, it works now. thank you

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 a pull request may close this issue.

2 participants