From 60a683243c499a273f1fe30d3971f6128038bf8f Mon Sep 17 00:00:00 2001 From: Lachlan Deakin Date: Tue, 26 Dec 2023 13:49:17 +1100 Subject: [PATCH] Add `ByteRange::offset` --- CHANGELOG.md | 1 + src/byte_range.rs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0595d52..ba4ed026 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Includes `DefaultStoreLocks` and `DisabledStoreLocks` implementations - Readable and writable stores include a `new_with_locks` method to choose the store lock implementation - Added `ArraySubset::new_with_ranges` + - Added `ByteRange::offset` ### Changed - **Breaking** `ReadableStorageTraits` is no longer a supertrait of `WritableStorageTraits` diff --git a/src/byte_range.rs b/src/byte_range.rs index 324a2741..f91c7ad9 100644 --- a/src/byte_range.rs +++ b/src/byte_range.rs @@ -56,6 +56,13 @@ impl ByteRange { } } + /// Return the internal offset of the byte range (which can be at its start or end). + #[must_use] + pub fn offset(&self) -> u64 { + let (Self::FromStart(offset, _) | Self::FromEnd(offset, _)) = self; + *offset + } + /// Return the length of a byte range. `size` is the size of the entire bytes. #[must_use] pub fn length(&self, size: u64) -> u64 {