From e72d11a572f431c008668ba409d191a504add9a5 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Thu, 31 Oct 2024 13:54:13 +0000 Subject: [PATCH] Rename HasLength to RangeLength and move it under 'util'. --- src/capture.rs | 3 ++- src/item.rs | 5 +---- src/util/id.rs | 16 ---------------- src/util/mod.rs | 20 ++++++++++++++++++++ 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/capture.rs b/src/capture.rs index bce2319d..af12b666 100644 --- a/src/capture.rs +++ b/src/capture.rs @@ -20,10 +20,11 @@ use crate::database::{ }; use crate::usb::{self, prelude::*}; use crate::util::{ - id::{Id, HasLength}, + id::Id, rcu::SingleWriterRcu, vec_map::{Key, VecMap}, Bytes, + RangeLength, fmt_count, fmt_size, }; diff --git a/src/item.rs b/src/item.rs index 265a9aff..30288db2 100644 --- a/src/item.rs +++ b/src/item.rs @@ -21,10 +21,7 @@ use crate::capture::{ INVALID_EP_ID, }; use crate::usb::{self, prelude::*, validate_packet}; -use crate::util::{ - id::HasLength, - Bytes, fmt_count, fmt_size, titlecase -}; +use crate::util::{Bytes, RangeLength, fmt_count, fmt_size, titlecase}; pub trait ItemSource { /// Fetch an item from the source by index, relative to either the root diff --git a/src/util/id.rs b/src/util/id.rs index d1e81f0d..6a37c11a 100644 --- a/src/util/id.rs +++ b/src/util/id.rs @@ -44,22 +44,6 @@ impl Debug for Id { } } -pub trait HasLength { - fn len(&self) -> u64; -} - -impl HasLength for Range> { - fn len(&self) -> u64 { - self.end.value - self.start.value - } -} - -impl HasLength for Range { - fn len(&self) -> u64 { - self.end - self.start - } -} - impl PartialEq> for Id { fn eq(&self, other: &Id) -> bool { self.value.eq(&other.value) diff --git a/src/util/mod.rs b/src/util/mod.rs index 7890e645..08d2b8ab 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,5 +1,7 @@ //! Utility code that doesn't belong anywhere specific. +use std::ops::Range; + use anyhow::{Error, bail}; use num_format::{Locale, ToFormattedString}; use humansize::{SizeFormatter, BINARY}; @@ -9,6 +11,8 @@ pub mod id; pub mod vec_map; pub mod rcu; +use id::Id; + pub fn fmt_count(count: u64) -> String { count.to_formatted_string(&Locale::en) } @@ -117,3 +121,19 @@ impl std::fmt::Display for Bytes<'_> { } } } + +pub trait RangeLength { + fn len(&self) -> u64; +} + +impl RangeLength for Range> { + fn len(&self) -> u64 { + self.end.value - self.start.value + } +} + +impl RangeLength for Range { + fn len(&self) -> u64 { + self.end - self.start + } +}