mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-08-22 10:46:38 +00:00
Use Cow<[u8]> for sort keys
This commit is contained in:
+7
-5
@@ -1,3 +1,5 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use garage_db as db;
|
||||
@@ -32,18 +34,18 @@ impl PartitionKey for FixedBytes32 {
|
||||
/// Trait for field used to sort data
|
||||
pub trait SortKey: Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static {
|
||||
/// Get the key used to sort
|
||||
fn sort_key(&self) -> &[u8];
|
||||
fn sort_key(&self) -> Cow<'_, [u8]>;
|
||||
}
|
||||
|
||||
impl SortKey for String {
|
||||
fn sort_key(&self) -> &[u8] {
|
||||
self.as_bytes()
|
||||
fn sort_key(&self) -> Cow<'_, [u8]> {
|
||||
Cow::from(self.as_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
impl SortKey for FixedBytes32 {
|
||||
fn sort_key(&self) -> &[u8] {
|
||||
self.as_slice()
|
||||
fn sort_key(&self) -> Cow<'_, [u8]> {
|
||||
Cow::from(self.as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user