kernel/utilities/
copy_range.rs

1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2026.
4
5//! A copyable twin of `core::ops::Range`.
6
7use core::ops::Range;
8
9/// A copyable twin of `core::ops::Range`.
10///
11/// This is useful to be able to store an equivalent of
12/// [`core::ops::Range`] in a type with `#[derive(Copy)]`
13#[derive(Copy, Clone, PartialEq, Eq, Debug)]
14pub struct CopyRange<Idx> {
15    pub start: Idx,
16    pub end: Idx,
17}
18
19impl<Idx> From<Range<Idx>> for CopyRange<Idx> {
20    fn from(r: Range<Idx>) -> Self {
21        CopyRange {
22            start: r.start,
23            end: r.end,
24        }
25    }
26}
27
28impl<Idx> From<CopyRange<Idx>> for Range<Idx> {
29    fn from(c: CopyRange<Idx>) -> Self {
30        Range {
31            start: c.start,
32            end: c.end,
33        }
34    }
35}