diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d90f446a..61f6c0ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,10 @@ name: CI on: [pull_request] +env: + CARGO_TERM_COLOR: always # Force Cargo to use colors + TERM: xterm-256color + jobs: build: runs-on: ubuntu-latest @@ -37,7 +41,7 @@ jobs: run: cargo clippy --tests --benches -- -D clippy::all - name: Test - run: cargo test + run: cargo test -- --color always env: RUST_BACKTRACE: 1 diff --git a/benchmarks/src/vec.rs b/benchmarks/src/vec.rs index b964b2eb..e6ac4115 100644 --- a/benchmarks/src/vec.rs +++ b/benchmarks/src/vec.rs @@ -29,7 +29,7 @@ impl Default for UnboundedVecN { } impl Storable for UnboundedVecN { - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Owned(self.0.clone()) } @@ -76,7 +76,7 @@ impl Default for BoundedVecN { } impl Storable for BoundedVecN { - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Owned(self.0.clone()) } diff --git a/docs/src/schema-upgrades.md b/docs/src/schema-upgrades.md index 326a57f0..6136599f 100644 --- a/docs/src/schema-upgrades.md +++ b/docs/src/schema-upgrades.md @@ -13,7 +13,7 @@ struct Asset { } impl Storable for Asset { - fn to_bytes(&self) -> std::borrow::Cow<[u8]> { + fn to_bytes(&self) -> std::borrow::Cow<'_, [u8]> { let mut bytes = vec![]; ciborium::ser::into_writer(&self, &mut bytes).unwrap(); Cow::Owned(bytes) diff --git a/examples/src/custom_types_example/src/lib.rs b/examples/src/custom_types_example/src/lib.rs index e6e7a70b..b6f682c0 100644 --- a/examples/src/custom_types_example/src/lib.rs +++ b/examples/src/custom_types_example/src/lib.rs @@ -24,7 +24,7 @@ struct UserProfile { // The `Storable` trait is already implemented for several common types (e.g. u64), // so you can use those directly without implementing the `Storable` trait for them. impl Storable for UserProfile { - fn to_bytes(&self) -> std::borrow::Cow<[u8]> { + fn to_bytes(&self) -> std::borrow::Cow<'_, [u8]> { Cow::Owned(Encode!(self).unwrap()) } diff --git a/examples/src/vecs_and_strings/src/lib.rs b/examples/src/vecs_and_strings/src/lib.rs index 1cb85cb5..e2773125 100644 --- a/examples/src/vecs_and_strings/src/lib.rs +++ b/examples/src/vecs_and_strings/src/lib.rs @@ -17,7 +17,7 @@ const MAX_USER_DATA_SIZE: u32 = 100; struct UserName(String); impl Storable for UserName { - fn to_bytes(&self) -> std::borrow::Cow<[u8]> { + fn to_bytes(&self) -> std::borrow::Cow<'_, [u8]> { // String already implements `Storable`. self.0.to_bytes() } @@ -39,7 +39,7 @@ impl Storable for UserName { struct UserData(Vec); impl Storable for UserData { - fn to_bytes(&self) -> std::borrow::Cow<[u8]> { + fn to_bytes(&self) -> std::borrow::Cow<'_, [u8]> { // Vec already implements `Storable`. self.0.to_bytes() } diff --git a/fuzz/fuzz_targets/data.rs b/fuzz/fuzz_targets/data.rs index 7eac81fe..0db642c1 100644 --- a/fuzz/fuzz_targets/data.rs +++ b/fuzz/fuzz_targets/data.rs @@ -20,7 +20,7 @@ pub struct UnboundedFuzzStruct { // The struct has size bounds reflected by Bound::Bounded::max_size impl Storable for BoundedFuzzStruct { - fn to_bytes(&self) -> std::borrow::Cow<[u8]> { + fn to_bytes(&self) -> std::borrow::Cow<'_, [u8]> { Cow::Owned(serde_cbor::ser::to_vec(self).unwrap()) } @@ -28,7 +28,7 @@ impl Storable for BoundedFuzzStruct { serde_cbor::ser::to_vec(&self).unwrap() } - fn from_bytes(bytes: std::borrow::Cow<[u8]>) -> Self { + fn from_bytes(bytes: std::borrow::Cow<'_, [u8]>) -> Self { let value: Self = serde_cbor::de::from_slice(bytes.as_ref()).unwrap(); value } @@ -41,7 +41,7 @@ impl Storable for BoundedFuzzStruct { // The struct has no size bounds impl Storable for UnboundedFuzzStruct { - fn to_bytes(&self) -> std::borrow::Cow<[u8]> { + fn to_bytes(&self) -> std::borrow::Cow<'_, [u8]> { Cow::Owned(serde_cbor::ser::to_vec(self).unwrap()) } @@ -49,7 +49,7 @@ impl Storable for UnboundedFuzzStruct { serde_cbor::ser::to_vec(&self).unwrap() } - fn from_bytes(bytes: std::borrow::Cow<[u8]>) -> Self { + fn from_bytes(bytes: std::borrow::Cow<'_, [u8]>) -> Self { let value: Self = serde_cbor::de::from_slice(bytes.as_ref()).unwrap(); value } diff --git a/src/btreemap.rs b/src/btreemap.rs index b5532522..a78e8a8f 100644 --- a/src/btreemap.rs +++ b/src/btreemap.rs @@ -172,7 +172,7 @@ const PAGE_SIZE_VALUE_MARKER: u32 = u32::MAX; /// } /// /// impl Storable for User { -/// fn to_bytes(&self) -> Cow<[u8]> { +/// fn to_bytes(&self) -> Cow<'_, [u8]> { /// let mut bytes = Vec::new(); /// // TODO: Convert your struct to bytes... /// Cow::Owned(bytes) @@ -1161,7 +1161,7 @@ where /// println!("{}: {}", key, value); /// } /// ``` - pub fn iter(&self) -> Iter { + pub fn iter(&self) -> Iter<'_, K, V, M> { self.iter_internal().into() } @@ -1184,7 +1184,7 @@ where /// println!("{}: {}", key, value); /// } /// ``` - pub fn range(&self, key_range: impl RangeBounds) -> Iter { + pub fn range(&self, key_range: impl RangeBounds) -> Iter<'_, K, V, M> { self.range_internal(key_range).into() } @@ -1194,7 +1194,7 @@ where /// Useful when `range(bound..)` skips the previous element. /// /// Returns an empty iterator if no smaller key exists. - pub fn iter_from_prev_key(&self, bound: &K) -> Iter { + pub fn iter_from_prev_key(&self, bound: &K) -> Iter<'_, K, V, M> { if let Some((start_key, _)) = self.range(..bound).next_back() { IterInternal::new_in_range(self, (Bound::Included(start_key), Bound::Unbounded)).into() } else { @@ -1211,36 +1211,36 @@ where /// The new name, [`iter_from_prev_key`], better reflects this behavior and /// improves code clarity. #[deprecated(note = "use `iter_from_prev_key` instead")] - pub fn iter_upper_bound(&self, bound: &K) -> Iter { + pub fn iter_upper_bound(&self, bound: &K) -> Iter<'_, K, V, M> { self.iter_from_prev_key(bound) } /// Returns an iterator over the keys of the map. - pub fn keys(&self) -> KeysIter { + pub fn keys(&self) -> KeysIter<'_, K, V, M> { self.iter_internal().into() } /// Returns an iterator over the keys of the map which belong to the specified range. - pub fn keys_range(&self, key_range: impl RangeBounds) -> KeysIter { + pub fn keys_range(&self, key_range: impl RangeBounds) -> KeysIter<'_, K, V, M> { self.range_internal(key_range).into() } /// Returns an iterator over the values of the map, sorted by key. - pub fn values(&self) -> ValuesIter { + pub fn values(&self) -> ValuesIter<'_, K, V, M> { self.iter_internal().into() } /// Returns an iterator over the values of the map where keys /// belong to the specified range. - pub fn values_range(&self, key_range: impl RangeBounds) -> ValuesIter { + pub fn values_range(&self, key_range: impl RangeBounds) -> ValuesIter<'_, K, V, M> { self.range_internal(key_range).into() } - fn iter_internal(&self) -> IterInternal { + fn iter_internal(&self) -> IterInternal<'_, K, V, M> { IterInternal::new(self) } - fn range_internal(&self, key_range: impl RangeBounds) -> IterInternal { + fn range_internal(&self, key_range: impl RangeBounds) -> IterInternal<'_, K, V, M> { if self.root_addr == NULL { // Map is empty. return IterInternal::null(self); @@ -2999,7 +2999,7 @@ mod test { #[derive(Clone, Ord, PartialOrd, Eq, PartialEq)] struct BuggyStruct; impl crate::Storable for BuggyStruct { - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Borrowed(&[1, 2, 3, 4]) } @@ -3142,7 +3142,7 @@ mod test { #[derive(PartialOrd, Ord, Clone, Eq, PartialEq, Debug)] struct T; impl Storable for T { - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Borrowed(&[1, 2, 3]) } @@ -3165,7 +3165,7 @@ mod test { #[derive(PartialOrd, Ord, Clone, Eq, PartialEq, Debug)] struct T2; impl Storable for T2 { - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Owned(vec![1, 2, 3]) } diff --git a/src/btreemap/node.rs b/src/btreemap/node.rs index 98114cb7..d0d75233 100644 --- a/src/btreemap/node.rs +++ b/src/btreemap/node.rs @@ -178,7 +178,7 @@ impl Node { /// Returns a reference to the entry at the specified index. #[inline(always)] - pub fn entry(&self, idx: usize, memory: &M) -> EntryRef { + pub fn entry(&self, idx: usize, memory: &M) -> EntryRef<'_, K> { (self.key(idx, memory), self.value(idx, memory)) } diff --git a/src/btreeset.rs b/src/btreeset.rs index b356d346..8257eec1 100644 --- a/src/btreeset.rs +++ b/src/btreeset.rs @@ -108,7 +108,7 @@ where /// } /// /// impl Storable for CustomType { -/// fn to_bytes(&self) -> Cow<[u8]> { +/// fn to_bytes(&self) -> Cow<'_, [u8]> { /// Cow::Owned(self.id.to_le_bytes().to_vec()) /// } /// @@ -482,7 +482,7 @@ where /// println!("{}", key); /// } /// ``` - pub fn iter(&self) -> Iter { + pub fn iter(&self) -> Iter<'_, K, M> { Iter::new(self.map.iter()) } @@ -506,7 +506,7 @@ where /// let range: Vec<_> = set.range(2..).collect(); /// assert_eq!(range, vec![2, 3]); /// ``` - pub fn range(&self, key_range: impl RangeBounds) -> Iter { + pub fn range(&self, key_range: impl RangeBounds) -> Iter<'_, K, M> { Iter::new(self.map.range(key_range)) } diff --git a/src/storable.rs b/src/storable.rs index 997a2623..f01f474d 100644 --- a/src/storable.rs +++ b/src/storable.rs @@ -14,7 +14,7 @@ pub trait Storable { /// Converts the element into a possibly borrowed byte slice. /// /// NOTE: `Cow` is used here to avoid unnecessary cloning. - fn to_bytes(&self) -> Cow<[u8]>; + fn to_bytes(&self) -> Cow<'_, [u8]>; /// Converts the element into an owned byte vector. /// @@ -28,7 +28,7 @@ pub trait Storable { const BOUND: Bound; /// Like `to_bytes`, but checks that bytes conform to declared bounds. - fn to_bytes_checked(&self) -> Cow<[u8]> { + fn to_bytes_checked(&self) -> Cow<'_, [u8]> { let bytes = self.to_bytes(); Self::check_bounds(&bytes); bytes @@ -195,7 +195,7 @@ impl fmt::Debug for Blob { impl Storable for Blob { #[inline] - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Borrowed(self.as_slice()) } @@ -243,7 +243,7 @@ impl Default for UnboundedVecN { } impl Storable for UnboundedVecN { - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Owned(self.0.clone()) } @@ -288,7 +288,7 @@ impl Default for BoundedVecN { } impl Storable for BoundedVecN { - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Owned(self.0.clone()) } @@ -322,7 +322,7 @@ impl Storable for BoundedVecN { impl Storable for () { #[inline] - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Borrowed(&[]) } @@ -346,7 +346,7 @@ impl Storable for () { impl Storable for Vec { #[inline] - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Borrowed(self) } @@ -365,7 +365,7 @@ impl Storable for Vec { impl Storable for String { #[inline] - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Borrowed(self.as_bytes()) } @@ -384,7 +384,7 @@ impl Storable for String { impl Storable for u128 { #[inline] - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Owned(self.into_bytes()) } @@ -406,7 +406,7 @@ impl Storable for u128 { impl Storable for u64 { #[inline] - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Owned(self.into_bytes()) } @@ -428,7 +428,7 @@ impl Storable for u64 { impl Storable for f64 { #[inline] - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Owned(self.into_bytes()) } @@ -450,7 +450,7 @@ impl Storable for f64 { impl Storable for u32 { #[inline] - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Owned(self.into_bytes()) } @@ -472,7 +472,7 @@ impl Storable for u32 { impl Storable for f32 { #[inline] - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Owned(self.into_bytes()) } @@ -494,7 +494,7 @@ impl Storable for f32 { impl Storable for u16 { #[inline] - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Owned(self.into_bytes()) } @@ -516,7 +516,7 @@ impl Storable for u16 { impl Storable for u8 { #[inline] - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Owned(self.into_bytes()) } @@ -537,7 +537,7 @@ impl Storable for u8 { } impl Storable for bool { - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Owned(if *self { 1_u8 } else { 0_u8 }.to_be_bytes().to_vec()) } @@ -563,7 +563,7 @@ impl Storable for bool { impl Storable for [u8; N] { #[inline] - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Borrowed(&self[..]) } @@ -588,7 +588,7 @@ impl Storable for [u8; N] { impl Storable for Reverse { #[inline] - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { self.0.to_bytes() } @@ -606,7 +606,7 @@ impl Storable for Reverse { } impl Storable for Option { - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { match self { Some(t) => { let mut bytes = t.to_bytes().into_owned(); @@ -658,7 +658,7 @@ impl Storable for Option { } impl Storable for Principal { - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Borrowed(self.as_slice()) } diff --git a/src/storable/tests.rs b/src/storable/tests.rs index 827133a3..84ce1f39 100644 --- a/src/storable/tests.rs +++ b/src/storable/tests.rs @@ -135,7 +135,7 @@ proptest! { fn to_bytes_checked_element_too_long_panics() { struct X; impl Storable for X { - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Borrowed(&[1, 2, 3, 4]) } @@ -160,7 +160,7 @@ fn to_bytes_checked_element_too_long_panics() { fn to_bytes_checked_unbounded_element_no_panic() { struct X; impl Storable for X { - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Borrowed(&[1, 2, 3, 4]) } @@ -182,7 +182,7 @@ fn to_bytes_checked_unbounded_element_no_panic() { fn to_bytes_checked_element_correct_size_no_panic() { struct X; impl Storable for X { - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Borrowed(&[1, 2, 3, 4]) } @@ -208,7 +208,7 @@ fn to_bytes_checked_element_correct_size_no_panic() { fn to_bytes_checked_fixed_element_wrong_size_panics() { struct X; impl Storable for X { - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Borrowed(&[1, 2, 3, 4]) } @@ -233,7 +233,7 @@ fn to_bytes_checked_fixed_element_wrong_size_panics() { fn to_bytes_checked_fixed_element_correct_size_no_panic() { struct X; impl Storable for X { - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Borrowed(&[1, 2, 3, 4, 5]) } diff --git a/src/storable/tuples.rs b/src/storable/tuples.rs index 7d429da5..26cebe84 100644 --- a/src/storable/tuples.rs +++ b/src/storable/tuples.rs @@ -8,7 +8,7 @@ where A: Storable, B: Storable, { - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Owned(into_bytes_inner_2(Self::BOUND, &self.0, &self.1)) } @@ -255,7 +255,7 @@ where // // Otherwise: // - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Owned(into_bytes_inner_3(&self.0, &self.1, &self.2)) } diff --git a/src/vec/tests.rs b/src/vec/tests.rs index b4c1bd2d..1c05a772 100644 --- a/src/vec/tests.rs +++ b/src/vec/tests.rs @@ -259,7 +259,7 @@ fn test_iter_count() { #[derive(Clone, Ord, PartialOrd, Eq, PartialEq)] struct BuggyStruct(Vec); impl crate::Storable for BuggyStruct { - fn to_bytes(&self) -> Cow<[u8]> { + fn to_bytes(&self) -> Cow<'_, [u8]> { Cow::Borrowed(&self.0) }