Git Product home page Git Product logo

Comments (5)

matklad avatar matklad commented on July 18, 2024 1

Tough question! API guidelines recommend taking Read/Write by value in API:

https://rust-lang.github.io/api-guidelines/interoperability.html#generic-readerwriter-functions-take-r-read-and-w-write-by-value-c-rw-value

However, as borsh impls are typically recursive, I am not entirely sure that it would be the right call in this case. Haven't thought too deeply about this, but it seems that taking an W in serialize and passing &mut W to recursive calls will cause excessive monomorphisations:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=c5b3ba6bd001be17dd2fb75bfd30a90e

So, I'd say the current signature is the right one for implementing serialization, no need to change or deprecate it. However, it's a bad API for using serialization, as it requires a trait import. Better to follow serde_json / bincode and introduce convenience top-level functions:

fn bosh::to_vec(valueh: &impl BorshSerialize) -> Vec<u8> {}
fn bosh::to_writer(value: &impl BorshSerialize, w: impl Writer) -> Vec<u8> {}
// Maybe?
fn bosh::to_base58(value: &impl BorshSerialize) -> String {}

from borsh-rs.

jstarry avatar jstarry commented on July 18, 2024 1

Ah, this was more nuanced than I expected. Additional high-level convenience functions would do the trick for us, thanks for looking into this!

from borsh-rs.

frol avatar frol commented on July 18, 2024

Thanks for bringing this topic! I have never evaluated this API. I will think through it once I have the capacity, meanwhile, I want to invite @evgenykuzyakov and @matklad to hear their thoughts.

from borsh-rs.

frol avatar frol commented on July 18, 2024

@jstarry Would you like to contribute a PR?

@matklad Thanks for the detailed overview 👍

from borsh-rs.

jstarry avatar jstarry commented on July 18, 2024

@frol no problem, just opened a PR

from borsh-rs.

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.