rust-embedded-community / serde-json-core

`serde-json` for `no_std` programs
Apache License 2.0
161 stars 59 forks source link

Add support for alloc::* types #4

Closed Pzixel closed 11 months ago

Pzixel commented 6 years ago

Currently I have following errors:

error[E0277]: the trait bound `alloc::String: serde::Serialize` is not satisfied
  --> C:\Users\Alex\Documents\Repo\pwasm-abi\derive\src\json.rs:14:10
   |
14 | #[derive(Serialize, Debug)]
   |          ^^^^^^^^^ the trait `serde::Serialize` is not implemented for `alloc::String`
   |
   = note: required by `serde::ser::SerializeStruct::serialize_field`

Could it be done in no-std scenario?

Pzixel commented 6 years ago

Yes, I carefully read that you don't support dynamic allocated types, but serde_json crate claims that they don't support no_std at all. So I'm in the situation where struct Foo(String) cannot be serialized, not with this crate or serde_json or any other.

sanmai-NL commented 6 years ago

@Pzixel: the solution would be for serde_json to use the alloc crate.

Pzixel commented 6 years ago

But they clearly say "It won't work, and even if it would, I won't support and/or accept any issues caused by this". It's kinda unstable situation.

sanmai-NL commented 6 years ago

Can you please provide a reference to that claim? A crate can be (not no_std) + alloc. For many operations, the alloc equivalents could be used.

Pzixel commented 6 years ago

https://github.com/serde-rs/json/issues/463#issuecomment-405388092

I don't intend to bring no-std support into serde_json as discussed previously in #362.

dtolnay commented 6 years ago

I reconsidered and would be willing to consider a serde_json PR to use alloc. https://github.com/serde-rs/json/issues/362#issuecomment-431186156

jonimake commented 5 years ago

I too would appreciate if the library used alloc crate types if there was an alloc feature enabled. Now I'm forced to use heapless String type instead of the alloc crate String type if I call to_string for example.

Xanewok commented 4 years ago

FWIW serde_json should support using only alloc via (now merged) https://github.com/serde-rs/json/pull/606

jordens commented 11 months ago

AFAICT this can be closed as both not pertinent to serde-json-core and resolved in serde-json.

eldruin commented 11 months ago

Thank you everybody!