From 4c7133055019c04a34953a96bb17effe50769ce9 Mon Sep 17 00:00:00 2001 From: Cody Wyatt Neiman Date: Mon, 16 Feb 2026 11:26:08 -0500 Subject: [PATCH] chore: resolve all missing_const_for_fn clippy lints --- roaring/src/bitmap/container.rs | 2 +- roaring/src/bitmap/inherent.rs | 2 +- roaring/src/bitmap/serialization.rs | 2 +- roaring/src/bitmap/store/array_store/mod.rs | 4 ++-- roaring/src/bitmap/store/array_store/visitor.rs | 4 ++-- roaring/src/bitmap/store/bitmap_store.rs | 10 +++++----- roaring/src/bitmap/store/interval_store.rs | 14 +++++++------- roaring/src/bitmap/store/mod.rs | 2 +- roaring/src/bitmap/util.rs | 2 +- roaring/src/lib.rs | 2 +- roaring/src/treemap/inherent.rs | 2 +- roaring/src/treemap/util.rs | 2 +- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/roaring/src/bitmap/container.rs b/roaring/src/bitmap/container.rs index b11a64468..5f281ce4f 100644 --- a/roaring/src/bitmap/container.rs +++ b/roaring/src/bitmap/container.rs @@ -26,7 +26,7 @@ pub(crate) struct Iter<'a> { } impl Container { - pub fn new(key: u16) -> Container { + pub const fn new(key: u16) -> Container { Container { key, store: Store::new() } } diff --git a/roaring/src/bitmap/inherent.rs b/roaring/src/bitmap/inherent.rs index cbaa6b5da..12eae5c94 100644 --- a/roaring/src/bitmap/inherent.rs +++ b/roaring/src/bitmap/inherent.rs @@ -20,7 +20,7 @@ impl RoaringBitmap { /// use roaring::RoaringBitmap; /// let rb = RoaringBitmap::new(); /// ``` - pub fn new() -> RoaringBitmap { + pub const fn new() -> RoaringBitmap { RoaringBitmap { containers: Vec::new() } } diff --git a/roaring/src/bitmap/serialization.rs b/roaring/src/bitmap/serialization.rs index cce50270f..a7d2f921e 100644 --- a/roaring/src/bitmap/serialization.rs +++ b/roaring/src/bitmap/serialization.rs @@ -325,7 +325,7 @@ impl RoaringBitmap { } } -fn header_size(size: usize, has_run_containers: bool) -> usize { +const fn header_size(size: usize, has_run_containers: bool) -> usize { if has_run_containers { // New format encodes the size (number of containers) into the 4 byte cookie // Additionally a bitmap is included marking which containers are run containers diff --git a/roaring/src/bitmap/store/array_store/mod.rs b/roaring/src/bitmap/store/array_store/mod.rs index 61967704c..cf31df3ce 100644 --- a/roaring/src/bitmap/store/array_store/mod.rs +++ b/roaring/src/bitmap/store/array_store/mod.rs @@ -58,11 +58,11 @@ pub(crate) fn last_contiguous_range_len(slice: &[u16]) -> usize { } impl ArrayStore { - pub fn new() -> ArrayStore { + pub const fn new() -> ArrayStore { ArrayStore { vec: vec![] } } - pub fn serialized_byte_size(cardinality: u64) -> usize { + pub const fn serialized_byte_size(cardinality: u64) -> usize { cardinality as usize * ARRAY_ELEMENT_BYTES } diff --git a/roaring/src/bitmap/store/array_store/visitor.rs b/roaring/src/bitmap/store/array_store/visitor.rs index d7293d7b2..80240398c 100644 --- a/roaring/src/bitmap/store/array_store/visitor.rs +++ b/roaring/src/bitmap/store/array_store/visitor.rs @@ -67,11 +67,11 @@ pub struct CardinalityCounter { } impl CardinalityCounter { - pub fn new() -> CardinalityCounter { + pub const fn new() -> CardinalityCounter { CardinalityCounter { count: 0 } } - pub fn into_inner(self) -> u64 { + pub const fn into_inner(self) -> u64 { self.count as u64 } } diff --git a/roaring/src/bitmap/store/bitmap_store.rs b/roaring/src/bitmap/store/bitmap_store.rs index ca32e2b52..d3173b434 100644 --- a/roaring/src/bitmap/store/bitmap_store.rs +++ b/roaring/src/bitmap/store/bitmap_store.rs @@ -26,7 +26,7 @@ impl BitmapStore { BitmapStore { len: 0, bits: Box::new([0; BITMAP_LENGTH]) } } - pub fn capacity(&self) -> usize { + pub const fn capacity(&self) -> usize { BITMAP_LENGTH * u64::BITS as usize } @@ -282,11 +282,11 @@ impl BitmapStore { ArrayStore::from_vec_unchecked(vec) } - pub fn len(&self) -> u64 { + pub const fn len(&self) -> u64 { self.len } - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.len == 0 } @@ -813,12 +813,12 @@ impl> DoubleEndedIterator for BitmapIter { impl> ExactSizeIterator for BitmapIter {} #[inline] -pub fn key(index: u16) -> usize { +pub const fn key(index: u16) -> usize { index as usize / 64 } #[inline] -pub fn bit(index: u16) -> usize { +pub const fn bit(index: u16) -> usize { index as usize % 64 } diff --git a/roaring/src/bitmap/store/interval_store.rs b/roaring/src/bitmap/store/interval_store.rs index 86b20223a..508b391ca 100644 --- a/roaring/src/bitmap/store/interval_store.rs +++ b/roaring/src/bitmap/store/interval_store.rs @@ -36,7 +36,7 @@ impl IntervalStore { Self::serialized_byte_size(self.run_amount()) } - pub fn serialized_byte_size(run_amount: u64) -> usize { + pub const fn serialized_byte_size(run_amount: u64) -> usize { RUN_NUM_BYTES + (RUN_ELEMENT_BYTES * run_amount as usize) } @@ -648,7 +648,7 @@ pub(crate) struct RunIter> { } impl> RunIter { - fn new(intervals: I) -> Self { + const fn new(intervals: I) -> Self { Self { forward_offset: 0, backward_offset: 0, intervals } } @@ -926,7 +926,7 @@ impl IntoIterator for &'_ Interval { } } -pub(crate) fn cmp_index_interval(index: u16, iv: Interval) -> Ordering { +pub(crate) const fn cmp_index_interval(index: u16, iv: Interval) -> Ordering { if index < iv.start { Ordering::Less } else if index > iv.end { @@ -942,15 +942,15 @@ impl Interval { Self { start, end } } - pub fn start(&self) -> u16 { + pub const fn start(&self) -> u16 { self.start } - pub fn end(&self) -> u16 { + pub const fn end(&self) -> u16 { self.end } - pub fn overlaps(&self, interval: &Self) -> bool { + pub const fn overlaps(&self, interval: &Self) -> bool { interval.start <= self.end && self.start <= interval.end } @@ -966,7 +966,7 @@ impl Interval { u64::from(self.end - self.start) + 1 } - pub fn is_full(&self) -> bool { + pub const fn is_full(&self) -> bool { self.start == 0 && self.end == u16::MAX } } diff --git a/roaring/src/bitmap/store/mod.rs b/roaring/src/bitmap/store/mod.rs index 11a3de0c0..7a693b5e7 100644 --- a/roaring/src/bitmap/store/mod.rs +++ b/roaring/src/bitmap/store/mod.rs @@ -42,7 +42,7 @@ pub(crate) enum Iter<'a> { } impl Store { - pub fn new() -> Store { + pub const fn new() -> Store { Store::Array(ArrayStore::new()) } diff --git a/roaring/src/bitmap/util.rs b/roaring/src/bitmap/util.rs index 80a4896ee..8e82a152f 100644 --- a/roaring/src/bitmap/util.rs +++ b/roaring/src/bitmap/util.rs @@ -3,7 +3,7 @@ use core::ops::{Bound, RangeBounds, RangeInclusive}; /// Returns the container key and the index /// in this container for a given integer. #[inline] -pub fn split(value: u32) -> (u16, u16) { +pub const fn split(value: u32) -> (u16, u16) { ((value >> 16) as u16, value as u16) } diff --git a/roaring/src/lib.rs b/roaring/src/lib.rs index f6c4453b1..e93dea3c2 100644 --- a/roaring/src/lib.rs +++ b/roaring/src/lib.rs @@ -51,7 +51,7 @@ pub struct NonSortedIntegers { impl NonSortedIntegers { /// Returns the number of elements that were - pub fn valid_until(&self) -> u64 { + pub const fn valid_until(&self) -> u64 { self.valid_until } } diff --git a/roaring/src/treemap/inherent.rs b/roaring/src/treemap/inherent.rs index bbc89f0aa..c053c6c7b 100644 --- a/roaring/src/treemap/inherent.rs +++ b/roaring/src/treemap/inherent.rs @@ -20,7 +20,7 @@ impl RoaringTreemap { /// use roaring::RoaringTreemap; /// let rb = RoaringTreemap::new(); /// ``` - pub fn new() -> RoaringTreemap { + pub const fn new() -> RoaringTreemap { RoaringTreemap { map: BTreeMap::new() } } diff --git a/roaring/src/treemap/util.rs b/roaring/src/treemap/util.rs index 55839c644..c127924d1 100644 --- a/roaring/src/treemap/util.rs +++ b/roaring/src/treemap/util.rs @@ -1,7 +1,7 @@ use core::ops::{Bound, RangeBounds, RangeInclusive}; #[inline] -pub fn split(value: u64) -> (u32, u32) { +pub const fn split(value: u64) -> (u32, u32) { ((value >> 32) as u32, value as u32) }