#How to serialize built-in struct that with Serde crate?
9 messages · Page 1 of 1 (latest)
No, you cannot make File serializable, due to Rust's orphan rule. Roughly, you can only implement a trait for a type, if your crate either defines the trait or the type. serde has the option to do a remote derive https://serde.rs/remote-derive.html which uses the with attribute to hook up custom serialization code https://serde.rs/field-attrs.html#with What do you expect a serialized File to look like? You can also skip the field with the skip attribute.
I am building my own version of Git in Rust, and the idea is that I need to serialize the struct above to store it in a file, and deserialize it back whenever I need it to get the original struct. I have no idea how to idea how to do it as easily as in Java
What's the goal of blob_saved_file?
Are you trying to store the bytes of a file inside another file?
Yeah, the git system will serialize the files changed in each commit, and store the serialized bytes in another file
I may be naive in my assumption, however, I don't believe that's how Git itself operates on files. In your case, that will be quite inefficient and you probably want to instead use something like a file hash
I'm with jonas wondering what you believe a serialized File type, or serialized file at all truly, would look like
Well... This project is inspired by a course project that I found online, and they did it in Java but I want to do it in Rust. Perhaps I should spend more time reading the doc for the project