sstadick / rust-lapper

Rust implementation of a fast, easy, interval tree library nim-lapper
https://docs.rs/rust-lapper
MIT License
55 stars 7 forks source link

Serialize and deserialize Interval and Lapper #11

Closed rkimoakbioinformatics closed 3 years ago

rkimoakbioinformatics commented 3 years ago

Hi, thanks for the crate. I made some structs with Interval and Lapper in them. I'd like to serialize and deserialize the structs, but am stuck in serializing and deserializing Interval and Lapper. Any advice on this would be appreciated.

sstadick commented 3 years ago

Thanks for opening an issue! I'll try to look into this in the next few days.

What I am thinking right now is to add Serialize / Deserialize to Interval and Lapper and put that behind a feature flag in cargo. I'm not sure how that will interact with num-traits though.

sstadick commented 3 years ago

To clarify, are you trying to use serde to include these structs in some larger format, or just persist them to disk?

sstadick commented 3 years ago

See the linked Draft PR for my first pass.

cargo run --example serde will print things out (not that that example data is not great, it's purely for showing that the lapper round trips nicely).

I need to add tests and feature gate serde / bincode before this can be released, but this is a start / template for how I would do it.

rkimoakbioinformatics commented 3 years ago

Thanks. Regarding your question, my structs had the following:

pub struct Rgs { pub ivs: Vec<Interval<u32, u32>>, pub lapper: Option<Lapper<u32, u32>>, }

I'm trying to save this as a file and then reconstruct it from the file.

rkimoakbioinformatics commented 3 years ago

I tried the feature/serde branch and the code compiled.

rkimoakbioinformatics commented 3 years ago

Thanks again.

sstadick commented 3 years ago

No problem! I just pushed a v1.0.0 release that has the serde features gated by with_serde. LMK if you run into any issues.