From 885bbdaf971a7706f0f29557e15791c4a0fc19a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Violeta=20Hern=C3=A1ndez?= Date: Thu, 17 Jun 2021 02:42:47 -0500 Subject: [PATCH] Implemented `SliceRange` for `RangeInclusive` (#911) --- src/base/matrix_slice.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/base/matrix_slice.rs b/src/base/matrix_slice.rs index ffe95c8a..129493d6 100644 --- a/src/base/matrix_slice.rs +++ b/src/base/matrix_slice.rs @@ -1,5 +1,5 @@ use std::marker::PhantomData; -use std::ops::{Range, RangeFrom, RangeFull, RangeTo}; +use std::ops::{Range, RangeFrom, RangeFull, RangeInclusive, RangeTo}; use std::slice; use crate::base::allocator::Allocator; @@ -806,6 +806,25 @@ impl SliceRange for RangeFull { } } +impl SliceRange for RangeInclusive { + type Size = Dynamic; + + #[inline(always)] + fn begin(&self, _: D) -> usize { + *self.start() + } + + #[inline(always)] + fn end(&self, _: D) -> usize { + *self.end() + 1 + } + + #[inline(always)] + fn size(&self, _: D) -> Self::Size { + Dynamic::new(*self.end() + 1 - *self.start()) + } +} + // TODO: see how much of this overlaps with the general indexing // methods from indexing.rs. impl> Matrix {