Giter Site home page Giter Site logo

Comments (2)

KodrAus avatar KodrAus commented on May 28, 2024 1

Thanks for helping out with this @TylerBloom 👍

There hasn't been any activity here for a while so I'll go ahead and close this one, but please feel free to open new issues with anything else you encounter.

from uuid.

TylerBloom avatar TylerBloom commented on May 28, 2024

Your issue is that a UUID (in JSON) is a string. You can see this if you perform the following test:

let id = uuid!("f4a9a11b-6e71-443d-9289-71a26fe6a018");
let s_id = serde_json::to_string(&id).unwrap();
// This check will fail
assert_eq!(s_id, "f4a9a11b-6e71-443d-9289-71a26fe6a018");

If you run this, you will get the following error:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `"\"f4a9a11b-6e71-443d-9289-71a26fe6a018\""`,
 right: `"f4a9a11b-6e71-443d-9289-71a26fe6a018"`'

However, you don't need to use serde_json. You can use Uuid::from_str to achieve what you want. The following runs without issue:

let id = uuid!("f4a9a11b-6e71-443d-9289-71a26fe6a018");
let from_str_id = Uuid::from_str("f4a9a11b-6e71-443d-9289-71a26fe6a018").unwrap();
assert_eq!(from_str_id, id);

Hope this helps!

from uuid.

Related Issues (20)

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.