Skip to content

Fix support for #![no_std] and serde #182

@vic1707

Description

@vic1707

Unable to compile in #![no_std] when using serde feature is enable and std feature is disabled.
The issue happens only with Deserialize.
I think the issue is the use of std::marker in the gen_impl_trait_serde_deserialize function, I'll make some tests and a PR asap.

using

[package]
name = "ttt"
version = "0.0.0"
edition = "2021"

[dependencies]
nutype = { version = "0.5.0", default-features = false, features = ["serde"] }
serde = { version = "1.0.210", default-features = false }

and

#![no_std]
use nutype::nutype;

#[nutype(derive(Deserialize))]
struct A(f32);

I get

   Compiling ttt v0.0.0 (C:\Users\vic1707\Documents\Perso\ttt)
error[E0433]: failed to resolve: could not find `std` in the list of imported crates
 --> src\lib.rs:4:1
  |
4 | #[nutype(derive(Deserialize))]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `std` in the list of imported crates
  |
  = help: consider importing this module:
          core::marker
  = note: this error originates in the attribute macro `nutype` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0433`.
error: could not compile `ttt` (lib) due to 1 previous error

Whereas this works fine (after enabling the derive feature ofc).

#![no_std]
use serde::Deserialize;

#[derive(Deserialize)]
struct A(f32);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions