ipld / libipld

Rust IPLD library
Apache License 2.0
135 stars 40 forks source link

Ipld as reference #181

Closed SionoiS closed 1 year ago

SionoiS commented 1 year ago

I want to get a reference to &Ipld without cloning the data into the enum.

Would be useful to serialize types with serde_json or serde_ipld_dagcbor without consuming them.

We know that some type could be used without cloning so maybe implement AsRef<Ipld> for builtin types as starting point?

vmx commented 1 year ago

I don't fully understand what you mean. Could you perhaps provide a minimal example?

Here's what I tried (I've added that to serde_ipld_dacbor/tests/ipld.rs to run it):

#[test]
fn test_ipld_reference() {
    let ipld = Ipld::String("Hello, world!".to_string());
    let data_ser = serde_ipld_dagcbor::to_vec(&ipld).unwrap();
    println!("{:?}", data_ser);
    assert!(false);
}
vmx commented 1 year ago

Oh, as I posted this, I saw that it's a pretty old issue. I was replying to a comment, that was since deleted. Does this mean that the issue got fixed? :)

MarshalX commented 1 year ago

@vmx ah sorry. I figured out how to do it. Thank you! Perhaps my question doesn't much about this issue 100%