serde-json-core icon indicating copy to clipboard operation
serde-json-core copied to clipboard

Add support for alloc::* types

Open Pzixel opened this issue 7 years ago • 8 comments
trafficstars

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 avatar Jul 18 '18 09:07 Pzixel

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.

Pzixel avatar Jul 18 '18 09:07 Pzixel

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

sanmai-NL avatar Oct 18 '18 14:10 sanmai-NL

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.

Pzixel avatar Oct 18 '18 15:10 Pzixel

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.

sanmai-NL avatar Oct 18 '18 15:10 sanmai-NL

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.

Pzixel avatar Oct 18 '18 17:10 Pzixel

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

dtolnay avatar Oct 18 '18 22:10 dtolnay

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.

jonimake avatar Jan 28 '19 09:01 jonimake

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

Xanewok avatar Jan 22 '20 23:01 Xanewok

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

jordens avatar Dec 30 '23 13:12 jordens

Thank you everybody!

eldruin avatar Dec 31 '23 10:12 eldruin