Git Product home page Git Product logo

Comments (2)

0xSiO avatar 0xSiO commented on May 24, 2024

There should be TryFrom conversions for Value into all equivalent native types - here's some pseudocode for example:

let some_hashmap: HashMap<String, i64> = HashMap::from_iter( ... );
let bolt_value = Value::from(some_hashmap); // This is a Value::Map
let native_value: HashMap<String, Value> = HashMap::try_from(bolt_value).unwrap();
// Or if your hashmap value type implements TryFrom<Value>...
let native_value: HashMap<String, i64> = HashMap::try_from(bolt_value).unwrap();

Something like that anyway... see here for more conversions. I noticed that some of them aren't showing up on docs.rs, which is a bit strange. Run cargo doc --open on bolt-proto and you should be able to see all of them.

Looking back at this, the Value API could use some simplification - it would be nice to be able to just match on a Value to get the native type:

match value {
    Value::Boolean(b) => ... // where b: bool
    Value::String(s) => ... // where s: String
    _ => ...
}

I will consider doing this at some point so there is no need for the TryFrom conversions - that was sort of an experiment that didn't work out very well.

I'll also see about implementing serde's Serialize trait so people don't need to write custom serializers.

from bolt-rs.

ppoliani avatar ppoliani commented on May 24, 2024

@lucis-fluxum thanks so much for the quick response. This is very helpful indeed.

I have actually found the TryFrom implementation by digging into the code and managed to write a simple serde-json serializer. But I totally agree with you; having that as part of the core crate would be super awesome.

from bolt-rs.

Related Issues (18)

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.