Skip to content

Commit b57ae65

Browse files
committed
encoding: tweaks
1 parent 4804df2 commit b57ae65

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/encoding/bincode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static BINCODE: LazyLock<bincode::DefaultOptions> = LazyLock::new(bincode::Defau
2323
/// Serializes a value using Bincode.
2424
pub fn serialize<T: Serialize>(value: &T) -> Vec<u8> {
2525
// Panic on failure, as this is a problem with the data structure.
26-
BINCODE.serialize(value).expect("bincode serialization failed")
26+
BINCODE.serialize(value).expect("value must be serializable")
2727
}
2828

2929
/// Deserializes a value using Bincode.

src/encoding/keycode.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Keycode is a lexicographical order-preserving binary encoding for use with
2-
//! keys. It is designed for simplicity, not efficiency (i.e. it does not use
3-
//! varints or other compression methods).
2+
//! keys in key/value stores. It is designed for simplicity, not efficiency
3+
//! (i.e. it does not use varints or other compression methods).
44
//!
55
//! Ordering is important because it allows limited scans across specific parts
66
//! of the keyspace, e.g. scanning an individual table or using an index range
@@ -56,9 +56,8 @@ use crate::error::{Error, Result};
5656
/// keep it simple.
5757
pub fn serialize<T: Serialize>(key: &T) -> Vec<u8> {
5858
let mut serializer = Serializer { output: Vec::new() };
59-
// Panic on serialization failures, as this is typically an issue with the
60-
// provided data structure.
61-
key.serialize(&mut serializer).expect("keycode serialization failed");
59+
// Panic on failure, as this is a problem with the data structure.
60+
key.serialize(&mut serializer).expect("key must be serializable");
6261
serializer.output
6362
}
6463

@@ -84,7 +83,7 @@ pub fn deserialize<'a, T: Deserialize<'a>>(input: &'a [u8]) -> Result<T> {
8483
/// prefixes after it.
8584
pub fn prefix_range(prefix: &[u8]) -> (Bound<Vec<u8>>, Bound<Vec<u8>>) {
8685
let start = Bound::Included(prefix.to_vec());
87-
let end = match prefix.iter().rposition(|b| *b != 0xff) {
86+
let end = match prefix.iter().rposition(|&b| b != 0xff) {
8887
Some(i) => Bound::Excluded(
8988
prefix.iter().take(i).copied().chain(std::iter::once(prefix[i] + 1)).collect(),
9089
),

src/encoding/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ pub trait Key<'de>: Serialize + Deserialize<'de> {
3737
}
3838

3939
/// Adds automatic Bincode encode/decode methods to value types. These are used
40-
/// not only for values in key/value storage engines, but also for e.g. network
41-
/// protocol messages and other values.
40+
/// for values in key/value storage engines, and also for e.g. network protocol
41+
/// messages and other values.
4242
pub trait Value: Serialize + DeserializeOwned {
4343
/// Decodes a value from a byte slice using Bincode.
4444
fn decode(bytes: &[u8]) -> Result<Self> {

0 commit comments

Comments
 (0)