Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions benchmarks/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl<const N: usize> Default for UnboundedVecN<N> {
}

impl<const N: usize> Storable for UnboundedVecN<N> {
fn to_bytes(&self) -> Cow<[u8]> {
fn to_bytes(&self) -> Cow<'_, [u8]> {
Cow::Owned(self.0.clone())
}

Expand Down Expand Up @@ -76,7 +76,7 @@ impl<const N: usize> Default for BoundedVecN<N> {
}

impl<const N: usize> Storable for BoundedVecN<N> {
fn to_bytes(&self) -> Cow<[u8]> {
fn to_bytes(&self) -> Cow<'_, [u8]> {
Cow::Owned(self.0.clone())
}

Expand Down
2 changes: 1 addition & 1 deletion docs/src/schema-upgrades.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/src/custom_types_example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
4 changes: 2 additions & 2 deletions examples/src/vecs_and_strings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -39,7 +39,7 @@ impl Storable for UserName {
struct UserData(Vec<u8>);

impl Storable for UserData {
fn to_bytes(&self) -> std::borrow::Cow<[u8]> {
fn to_bytes(&self) -> std::borrow::Cow<'_, [u8]> {
// Vec<u8> already implements `Storable`.
self.0.to_bytes()
}
Expand Down
8 changes: 4 additions & 4 deletions fuzz/fuzz_targets/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ 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())
}

fn into_bytes(self) -> Vec<u8> {
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
}
Expand All @@ -41,15 +41,15 @@ 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())
}

fn into_bytes(self) -> Vec<u8> {
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
}
Expand Down
28 changes: 14 additions & 14 deletions src/btreemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1161,7 +1161,7 @@ where
/// println!("{}: {}", key, value);
/// }
/// ```
pub fn iter(&self) -> Iter<K, V, M> {
pub fn iter(&self) -> Iter<'_, K, V, M> {
self.iter_internal().into()
}

Expand All @@ -1184,7 +1184,7 @@ where
/// println!("{}: {}", key, value);
/// }
/// ```
pub fn range(&self, key_range: impl RangeBounds<K>) -> Iter<K, V, M> {
pub fn range(&self, key_range: impl RangeBounds<K>) -> Iter<'_, K, V, M> {
self.range_internal(key_range).into()
}

Expand All @@ -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<K, V, M> {
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 {
Expand All @@ -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<K, V, M> {
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<K, V, M> {
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<K>) -> KeysIter<K, V, M> {
pub fn keys_range(&self, key_range: impl RangeBounds<K>) -> 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<K, V, M> {
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<K>) -> ValuesIter<K, V, M> {
pub fn values_range(&self, key_range: impl RangeBounds<K>) -> ValuesIter<'_, K, V, M> {
self.range_internal(key_range).into()
}

fn iter_internal(&self) -> IterInternal<K, V, M> {
fn iter_internal(&self) -> IterInternal<'_, K, V, M> {
IterInternal::new(self)
}

fn range_internal(&self, key_range: impl RangeBounds<K>) -> IterInternal<K, V, M> {
fn range_internal(&self, key_range: impl RangeBounds<K>) -> IterInternal<'_, K, V, M> {
if self.root_addr == NULL {
// Map is empty.
return IterInternal::null(self);
Expand Down Expand Up @@ -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])
}

Expand Down Expand Up @@ -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])
}

Expand All @@ -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])
}

Expand Down
2 changes: 1 addition & 1 deletion src/btreemap/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl<K: Storable + Ord + Clone> Node<K> {

/// Returns a reference to the entry at the specified index.
#[inline(always)]
pub fn entry<M: Memory>(&self, idx: usize, memory: &M) -> EntryRef<K> {
pub fn entry<M: Memory>(&self, idx: usize, memory: &M) -> EntryRef<'_, K> {
(self.key(idx, memory), self.value(idx, memory))
}

Expand Down
6 changes: 3 additions & 3 deletions src/btreeset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
/// }
///
Expand Down Expand Up @@ -482,7 +482,7 @@ where
/// println!("{}", key);
/// }
/// ```
pub fn iter(&self) -> Iter<K, M> {
pub fn iter(&self) -> Iter<'_, K, M> {
Iter::new(self.map.iter())
}

Expand All @@ -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<K>) -> Iter<K, M> {
pub fn range(&self, key_range: impl RangeBounds<K>) -> Iter<'_, K, M> {
Iter::new(self.map.range(key_range))
}

Expand Down
Loading