borsh-rs icon indicating copy to clipboard operation
borsh-rs copied to clipboard

Add derive macro attribute to specify borsh crate

Open quasiyoke opened this issue 1 year ago • 2 comments

Add derive macro attribute like serde container's crate attr (test):

  1. To be able to work with byte blobs built with legacy borsh.
  2. To be able to use re-exported borsh crate for BorshSerialize, BorshDeserialize derives.
#[derive(borsh::BorshSerialize)]
#[borsh(crate = "legacy_borsh")]
struct NearLog;

quasiyoke avatar Jul 18 '22 12:07 quasiyoke

@quasiyoke Good point! Will you be up to prepare and submit a PR?

frol avatar Jul 18 '22 17:07 frol

I have this need also, and i can try and prepare a PR

cybersoulK avatar Aug 13 '22 14:08 cybersoulK

@cybersoulK do you work on this?

iho avatar Jun 06 '23 21:06 iho

Can I work on this ?

GentBinaku avatar Jul 11 '23 12:07 GentBinaku

@iho I didn't end up working on it, because my new implementation does not require it. Borsh is only a way to serialize data, which should be imported in the original project anyways. The library allows the user to implement its own serialization method, which is a much better approach. if you want to abstract borsh derives, you can use macro_rules_attribute to create a local abstraction, instead of making it opinionated in the library. I do this to abstract a common group of derives. but if it's only borsh, i would write it explicitely, since it's clearer on what's going in the whole picture of the codes.

cybersoulK avatar Jul 12 '23 00:07 cybersoulK