Giter VIP home page Giter VIP logo

Comments (4)

Yarn avatar Yarn commented on June 3, 2024 2

You can avoid the issue with

serde-hjson = { version = "0.9", default-features = false }

this will disable preservation of key order


I made a version that patches the issue (it was and still is UB but it seems to work for now).
https://github.com/Yarn/hjson-rust/tree/unitialized_fix
https://github.com/Yarn/linked-hash-map/tree/hjson_fix

you can use it with

serde-hjson = { git = "https://github.com/Yarn/hjson-rust.git", rev = "ae3a336153d0c4f757beb848d2059123be00cb75" }

My workaround for the older version of serde is to read the file to a serde_hjson::Value then using an old version of serde_json to write json to a string then reading that string using a new version of serde_json

in Cargo.toml

serde-hjson = { git = "https://github.com/Yarn/hjson-rust.git", rev = "ae3a336153d0c4f757beb848d2059123be00cb75" }
serde_json = "1.0"
serde_json_old = { package = "serde_json", version = "0.8.6" }

in your code assuming Thing implements serde 1.0 deserialize

let mut f = std::fs::File::open(path).unwrap();
let a: serde_hjson::Value = serde_hjson::from_reader(f).unwrap();
let b = serde_json_old::to_string(&a).unwrap();
let thing: Thing = serde_json::from_str(&b).unwrap();

from hjson-rust.

Yarn avatar Yarn commented on June 3, 2024 2

#24

sometimes the solution is in the obvious place

from hjson-rust.

cheradenine avatar cheradenine commented on June 3, 2024

what's the story with your nu_hjson fork, @jonathandturner ? I can't find the source and it looks like it is also on an older version of serde (0.8.23). From the issues list here there seems to be no viable hjson package for rust currently.

from hjson-rust.

dessalines avatar dessalines commented on June 3, 2024

@Nutomic has tried swapping out linked_hash_map (the dead library causing this error) for hashlink (a new, well maintained one). However unfortunately it has this error:

            #[inline]
            fn visit_map<'de, V>(&mut self, visitor: V) -> Result<Value, V::Error>
                where V: de::MapVisitor,
                // where V: de::MapAccess<'de>,
            {
                let values = try!(MapVisitor::default().visit_map(visitor));
                Ok(Value::Object(values))
            }

error:

error[E0599]: no method named `visit_map` found for struct `LinkedHashMapVisitor<_, _>` in the current scope
   --> src/value.rs:442:57
    |
442 |                 let values = try!(MapVisitor::default().visit_map(visitor));
    |                                                         ^^^^^^^^^ method not found in `LinkedHashMapVisitor<_, _>`
    |
    = help: items from traits can only be used if the trait is in scope
    = note: the following trait is implemented but not in scope; perhaps add a `use` for it:
            `use serde::de::Visitor;`

This is because hashlink requires serde::de::MapAccess rather than serde::de::MapVisitor, which unfortunately only newer versions of serde have.

I tried upgrading the serde version from 0.8.0, but it causes ~100 errors that I'm not familiar enough with serde to fix.

edit: [here's the code: Nutomic/hjson-rust#use-hashlink

from hjson-rust.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.