Holochain Forum

A function which returns "f64" won't compile --> `convert::From<i64>` is not implemented for `hdk::holochain_json_api::json::JsonString`

A function like this won’t compile:

pub fn handle_my_func1(name: String) -> ZomeApiResult<f64> {

Or any other function which returns i64, or (String, f64) and so on.

The reason is:

| |_^ the trait `std::convert::From<i64>` is not implemented for `hdk::holochain_json_api::json::JsonString`

It’s not implemented on purpose, correct? Then how am I supposed to return f64 and other types?

@alx it’s not necessarily on purpose…

maybe it needs to be added to the list here https://github.com/holochain/holochain-serialization/blob/develop/crates/holochain_json_api/src/json.rs

for more complex/custom types you’d need to implement From which can be done manually or using the derive macros or other utilities in the serialization crate

more info on json/data round trips here https://github.com/holochain/holochain-rust/blob/develop/doc/holochain_101/src/json_string.md

1 Like

How should I use f64 now given that’s not implemented in Holochain now, nor can I implement it in my app myself because Rust doesn’t allow implementing such stuff outside of an original crate?

@alx probably impossible because of the compiler being conservative about potentially duplicate implementations like you said

Put a PR up for serialisation and I’ll review and merge it

@alx @ me on github once it is up