sstadick / rust-lapper

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

Using lapper in helix #3

Closed ayanko closed 4 years ago

ayanko commented 4 years ago

Hi,

How to share lapper instance? I am trying to pass lapper instance to to another structure but I have compilation error.

Code:

#[macro_use]
extern crate helix;
extern crate rust_lapper;

use rust_lapper::{Interval, Lapper};

type IntervalType = (u32, u32);
type Iv = Interval<u32>;

ruby! {
    class LapperSearchOne {
        struct {
            lapper: Lapper<u32>
        }

        def initialize(helix, intervals: Vec<IntervalType>) {
            let data = intervals.into_iter().map(|interval|
                Iv{start: interval.0, stop: interval.1, val: 0}
            ).collect();
            LapperSearchOne { helix, lapper: Lapper::new(data) }
        }
    }
}

Error:

error[E0277]: the trait bound `rust_lapper::Lapper<u32>: std::clone::Clone` is not satisfied
  --> src/lib.rs:14:13
   |
14 |             lapper: Lapper<u32>
   |             ^^^^^^^^^^^^^^^^^^^ the trait `std::clone::Clone` is not implemented for `rust_lapper::Lapper<u32>`
   |
   = note: required by `std::clone::Clone::clone`

Is this due to missing Clone in macro on line https://github.com/sstadick/rust-lapper/blob/master/src/lib.rs#L92 ?

How to fix it? Thank you in advance.

sstadick commented 4 years ago

Well, just to clarify, the lapper instance is sharable as is via references etc. Clone is not 'sharing' it's creation of a new thing. If I'm understanding Helix correctly, the struct implements clone, so all the fields of the struct must also implement clone. I'd verify that there is no way to do what you want to do without clone on Lapper first.

However, I pushed a new version with Lapper implementing Clone. Try v0.4.4 and see if that fixes it for you.

ayanko commented 4 years ago

I'd verify that there is no way to do what you want to do without clone on Lapper first.

Well... After learning more docs I found the way. It's possible with this one:

https://doc.rust-lang.org/std/rc/

But anyway thank you for new release.

sstadick commented 4 years ago

Reopen if you find any issues!