From 071a1bc96ed068aa41096668ff28e56246d111bf Mon Sep 17 00:00:00 2001 From: Vince Buffalo Date: Tue, 5 Mar 2024 20:24:36 -0800 Subject: [PATCH] Added `GRanges::clone_with_data()`. --- src/granges.rs | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/granges.rs b/src/granges.rs index 62e2b8c..9f386b1 100644 --- a/src/granges.rs +++ b/src/granges.rs @@ -140,20 +140,23 @@ where } } -// NOTE: not safe -- not used, so removed. -// impl GRanges -// where -// C: RangeContainer + Clone, -// { -// /// Create a new [`GRanges`] object by cloning the ranges of this one, -// /// and associating the supplied data with it (this consumes the data). -// pub fn clone_with_data(&self, data: Option) -> GRanges { -// GRanges { -// ranges: self.ranges.clone(), -// data, -// } -// } -// } +impl GRanges +where + C: RangeContainer + Clone, +{ + /// Create a new [`GRanges`] object by cloning the ranges of this one, + /// and associating the supplied data with it (this consumes the data). + /// + /// Note that this is *not* guaranteed to be safe - a panic may result + /// if the developer has used ranges with invalid indices (e.g. + /// do not point to valid elements in the data container). + pub fn clone_with_data(&self, data: Option) -> GRanges { + GRanges { + ranges: self.ranges.clone(), + data, + } + } +} impl GRangesEmpty where