json-ld icon indicating copy to clipboard operation
json-ld copied to clipboard

Example in README fails to compile and run

Open weegeekps opened this issue 3 years ago • 3 comments

I've been attempting to use this library in a project but have been having no success due to unsatisfied trait bounds on ijson::IValue. This is reproducible in your own example code in the README.md file.

The output from Cargo:

error[E0599]: the method `expand` exists for struct `IValue`, but its trait bounds were not satisfied
  --> src/main.rs:23:28
   |
23 |     let expanded_doc = doc.expand::<context::Json<IValue>, _>(&mut loader).await?;
   |                            ^^^^^^ method cannot be called on `IValue` due to unsatisfied trait bounds
   |
  ::: /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/ijson-0.1.3/src/value.rs:58:1
   |
58 | pub struct IValue {
   | -----------------
   | |
   | doesn't satisfy `IValue: Document<_>`
   | doesn't satisfy `IValue: generic_json::Json`
   |
   = note: the following trait bounds were not satisfied:
           `IValue: generic_json::Json`
           which is required by `IValue: Document<_>`

This error is happening with the nightly toolchain on mac:

rustc 1.59.0-nightly (5531927e8 2021-12-16)

My assumption is that this has something to do with the version of generic-json that version 0.5.0 of this crate uses. Any help or guidance on how to handle this issue would be welcome. Thank you.

weegeekps avatar Dec 17 '21 21:12 weegeekps

Hey, sorry for the delay. json-ld is independent from th JSON implementation, you can use serde_json::Value or ijson::IValue or whatever as long as it implements the generic-json::Json trait. For ijson, this implementation is provided by the generic-json crate by enabling the ijson-impl feature. Did you enable it?

There is a similar implementation for serde_json with the serde_json-impl feature.

timothee-haudebourg avatar Jan 14 '22 14:01 timothee-haudebourg

Hi could this be added to the docs. I got caught out by this and it took me ages to figure out it wasn't a problem with my code, or crate versions.

apps4uco avatar Mar 10 '22 17:03 apps4uco

Yes I agree, there is a lot a catch up to do in the doc, unfortunately I have a lot going on on my plate so it'll take a bit of time.

timothee-haudebourg avatar Mar 15 '22 13:03 timothee-haudebourg

generic-json has been dropped in favor of json-syntax in the new version 0.9.1. It caused too many issues, had a tedious API, wasn't compatible with every major JSON implementations and required unstable trait aliases. Compatibility with ijson will have to be discussed on the json-syntax repo.

Now all the examples in the README are working.

timothee-haudebourg avatar Dec 09 '22 16:12 timothee-haudebourg